Skip to content

Display

Using the methods below you will be able to interact with the display.

Getting display and viewport size

Using the display size and get viewport size method, you can respectively, get the screen dimension (width and height) in pixels and the current viewport width and height.

# Defining a variable to receive the display size.
display_size = bot.display_size()

# Print the display size in pixels.
print(display_size)

# Defining a variable to receive the viewport size.
viewport_size = bot.get_viewport_size()

# Print the viewport size.
print(viewport_size)
import org.openqa.selenium.Dimension;

// Defining a variable to receive the display size.
Dimension displaySize = displaySize();

// Print the display size in pixels.
System.out.println(displaySize);

// Defining a variable to receive the viewport size.
Dimension viewportSize = getViewportSize();

// Print viewport size containing the current the viewport width and height.
System.out.println(viewportSize);

Setting screen resolution

With set screen resolution method, you will be to able configures the browser dimensions.

# Setting the width and height to open the browser as desired dimensions.
bot.set_screen_resolution(600, 1200)
// Setting the width and height to open the browser as desired dimensions.
setScreenResolution(600, 1200);

Getting screenshot

With the get screenshot method it is possible to take a screenshot and save it in any directory passing the path as a parameter.

# Take a screenshot, save it if filepath is given and return the screenshot Image object.
bot.get_screenshot(filepath='my_screenshot_with_method_get_screenshot.png')

Tip

The method takes an optional parameter region which is a tuple with values ​​of left, top, width and height to cut part the screen. Learn more at the full API documentation.

// Take a screenshot and return the screenshot MarvinImage object.
MarvinImage screen = getScreenshot();

Getting partial screenshot

As we saw above, it is possible to take a screenshot of the entire screen. Using the screen cut method and passing as parameter the x and y coordinates along with the width and height, only the indicated area will be collected.

# Capturing part of the screen.
screen_cut = bot.screen_cut(x=702, y=380, width=120, height=80)

# The variable `screen_cut` is the screenshot Image object returned.
import dev.botcity.framework.web.Region;

Region region = new Region(702, 380, 120, 80);

// Capturing part of the screen.
MarvinImage screen = screenCut(region);

// The variable `screen` is the screenshot MarvinImage object returned.

Saving a screenshot

The save screenshot has pretty much the same functionality as the get_screenshot and screenshot methods.

The only difference is that it does not return an Image object but instead, it simply saves the image on disk.

# Take and save a screeshot.
bot.save_screenshot("screenshot.png")
// Take and save a screeshot.
saveScreenshot("screenshot.png");

Maximizing the Browser Window

# Maximize the window.
bot.maximize_window()
// Maximize the window.
maximizeWindow();