Screen Driver Element
Screen Driver Element
ScreenElement is a certain rectangular area of the screen. It is possible to search for and get this element only by image (see Find Elements section on drive page):
contains
This method accepts another "ScreenElement" object and return "true" of current element contains another image element inside.
ScreenElement mainWindow = driver.findElement(ScreenSearch.image("main-window-title.png")); ScreenElement okButton = driver.findElement(ScreenSearch.image("ok-button.png")); boolean mainWindowHasOkButton = mainWindow.contains(okButton);
copyToClipboard
Clicks inside target image element, presses "Ctrl+A" (select all) keys combination and then "Ctrl+C" (copy) keys combination to save selected text into buffer.
driver.findElement(ScreenSearch.image("first-name-input-area.png")).copyToClipboard();
doubleClick
Performs double click on the center of target image element.
driver.findElement(ScreenSearch.image("edit-area.png")).doubleClick();
getOcrText
OCR module recognizes and returns a text from target image element.
String text = driver.findElement(ScreenSearch.image("user-input-field.png")).getOcrText();
getRegion
Returns o
rg.sikuli.script.Region
object which contains a lot of useful methods.
For example. region's methods getX()
, getY()
, getW()
and getH()
identify the position on screen and the element size.
Region region = driver.findElement(ScreenSearch.image("user-input-field.png")).getRegion(); System.out.println("x: " + region.getX()); System.out.println("y: " + region.getY()); System.out.println("width: " + region.getW()); System.out.println("height: " + region.getH());
getUrl
Returns the relative path to the image you are searching by.
String userInputFieldPngUrl = driver.findElement(ScreenSearch.image("user-input-field.png")).getUrl();
highlight
Highlights the region for some period of time. Accepts the time in seconds as double.
driver.findElement(ScreenSearch.image("user-input-field.png")).highlight(10);
rightClick
Performs right click on the center of target image element.
driver.findElement(ScreenSearch.image("user-input-field.png")).rightClick();
keyDown
Presses down and holds the key. Accepts keycode from org.sikuli.script.Key
ScreenElement mainWindowElement = driver.findElement(ScreenSearch.image("main-window.png")); mainWindowElement.keyDown(Key.ALT); mainWindowElement.keyDown(Key.F4); mainWindowElement.keyUp();
keyUp
Releases all the pressed keys. Can also accept a keycode from org.sikuli.script.Key
if the specific key must be released
ScreenElement mainWindowElement = driver.findElement(ScreenSearch.image("main-window.png")); mainWindowElement.keyDown(Key.ALT); mainWindowElement.keyDown(Key.F4); mainWindowElement.keyUp();
pasteFromClipboard
Clicks inside target image element and presses "Ctrl+V" (paste) keys combination.
driver.findElement(ScreenSearch.image("first-name-input-area.png")).pasteFromClipboard();
sendEnter
Sends enter key inside target image element.
driver.findElement(ScreenSearch.image("first-name-input-area.png")).sendEnter();