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.
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.
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.
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.
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.