Package dev.botcity.framework.bot
Class WebBot
java.lang.Object
dev.botcity.framework.bot.WebBot
Base class for Web Bots.
Users must implement the `action` method in their classes.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
activateTab
(String handle) Activate a tab given by the handle.void
Add an image into the state image map.void
back()
Pressing the browser’s back button.void
Press Backspace key.void
backspace
(int wait) Press Backspace key.void
Opens the browser on the given URL.void
click()
Click on the last found element.void
click
(int wait) Click on the last found element.void
Click on the last found element.void
Left click on the last found element.void
clickAt
(int x, int y) Click at the coordinate defined by x and y.void
clickAt
(int x, int y, int clicks) Click at the coordinate defined by x and y.void
Click at the coordinate defined by x and y.void
Click on the element.void
Click on the element.void
clickRelative
(int x, int y) Click Relative on the last found element.void
Close the current active page (tab or window).void
controlA()
Press keys CTRL+A.void
controlA
(int wait) Press keys CTRL+A.void
controlC()
Press keys CTRL+C.void
controlC
(int wait) Press keys CTRL+C.void
controlV()
Press keys CTRL+X.void
copyToClipboard
(String text) Copy content to the clipboard.void
Create a new tab and navigate to the given URL.void
createWindow
(String url) Creates a new window with the given URL.void
delete()
Press key Delete.void
delete
(int wait) Press key Delete.org.openqa.selenium.Dimension
Returns the display size in pixels.void
Double Click on the last found element.void
doubleClick
(int wait) Double Click on the last found element.void
doubleClickRelative
(int x, int y) Double Click Relative on the last found element.void
enter()
Press key Enter.void
enter
(int wait) void
enterIframe
(org.openqa.selenium.WebElement element) Switch the WebBot driver to the specified iframe.executeJavascript
(String code, Object... args) Execute the given javascript code.boolean
Find an element defined by label on screen until a timeout happens.boolean
Find an element defined by label on screen until a timeout happens.boolean
Find an element defined by label on screen until a timeout happens.Find all elements defined by label on screen until a timeout happens.findAll
(String label, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find all elements defined by label on screen until a timeout happens.findAll
(org.marvinproject.framework.image.MarvinImage visualElem, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find all elements defined by label on screen until a timeout happens.org.openqa.selenium.WebElement
findElement
(org.openqa.selenium.By by) Find an element using the specified selector with selector type specified by `by`.org.openqa.selenium.WebElement
findElement
(org.openqa.selenium.By by, boolean ensureVisible, boolean ensureClickable, long waitingTime) Find an element using the specified selector with selector type specified by `by`.List<org.openqa.selenium.WebElement>
findElements
(org.openqa.selenium.By by) Find elements using the specified selector with selector type specified by `by`.List<org.openqa.selenium.WebElement>
findElements
(org.openqa.selenium.By by, boolean ensureVisible, long waitingTime) Find elements using the specified selector with selector type specified by `by`.findMultiple
(List<String> labels, double matching, long waitingTime) Find multiple elements defined by label on screen until a timeout happens.findMultiple
(List<String> labels, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find multiple elements defined by label on screen until a timeout happens.boolean
Find an element defined by label on screen until a timeout happens.boolean
Find an element defined by label on screen until a timeout happens.boolean
Find an element defined by label on screen until a timeout happens.boolean
findUntil
(String label, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find an element defined by label on screen until a timeout happens.boolean
findUntil
(org.marvinproject.framework.image.MarvinImage visualImage, int threshold, boolean grayscale, double matching) Find an element defined by label on screen until a timeout happens.boolean
findUntil
(org.marvinproject.framework.image.MarvinImage visualElem, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find an element defined by label on screen until a timeout happens.void
forward()
Pressing the browser’s forward button.Get the current content in the clipboard.org.openqa.selenium.WebDriver
The WebDriver driver instance.getElementCoords
(String label, double matching) Find an element defined by label on screen and returns its coordinates.getElementCoords
(String label, Region region, double matching) Find an element defined by label on screen and returns its coordinates.getElementCoordsCentered
(String label, double matching) Find an element defined by label on screen and returns its centered coordinates.int
getFileCount
(String path, String fileExtension) Get the total number of files of the same type.org.openqa.selenium.Alert
Return the last found dialog.Return the last element found.int
getLastX()
Return the x position of the last element found.int
getLastY()
Return the y position of the last element found.org.openqa.selenium.Dimension
Returns the browser current page size.org.marvinproject.framework.image.MarvinImage
Capture and returns a screenshot from the browser.org.marvinproject.framework.image.MarvinImage
getScreenImage
(Region region) Capture and returns a screenshot from the browser.org.marvinproject.framework.image.MarvinImage
Capture a screenshot.getTabs()
Get a list of tab handlers.org.openqa.selenium.Dimension
Returns the browser current viewport size.boolean
handleJsDialog
(boolean accept) Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).boolean
handleJsDialog
(boolean accept, String promptText) Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).void
Hold key Shift.void
holdShift
(int wait) Hold key Shift.void
installFirefoxExtension
(String extensionPath) Install an extension in the Firefox browser.void
Type a text char by char (individual key events).void
keyEnd()
Press key End.void
keyEnd
(int wait) Press key End.void
keyEnter()
Press key Enter.void
keyEnter
(int wait) Press key Enter.void
keyEsc()
Press key Esc.void
keyEsc
(int wait) Press key Esc.void
keyHome()
Press key Home.void
keyHome
(int wait) Press key Home.void
keyRight
(int wait) Press key Right.void
Leave the iframe and switch the WebBot driver to the default content.void
Shortcut to maximize window on Windows OS.void
Holds down the requested mouse button.void
mouseDown
(int wait) Holds down the requested mouse button.void
mouseMove
(int x, int y) Mouse the move to the coordinate defined by x and y.void
mouseUp()
Releases the requested mouse button.void
mouseUp
(int wait) Releases the requested mouse button.void
move()
Move to the center position of last found item.void
move
(int wait) Move to the center position of last found item.void
moveRandom
(int rangeX, int rangeY) Move randomly along the given x, y range.void
moveRelative
(int x, int y) Move the mouse relative to its current position.void
moveTo
(int x, int y) Move the mouse relative to its current position.void
moveTo
(int x, int y, int wait) Move the mouse relative to its current position.void
navigateTo
(String url) Opens the browser on the given URL.void
pageDown()
Press Page Down keyvoid
pageDown
(int wait) Press Page Down key.org.jsoup.nodes.Document
Returns the active page source.Returns the active page title.void
pageUp()
Press Page Up keyvoid
pageUp
(int wait) Press Page Up key.void
paste()
Paste content from the clipboard.printPdf()
Print the current page as a PDF file.Print the current page as a PDF file.Print the current page as a PDF file.void
refresh()
Refresh the current page.void
Release key Shift.void
Right click on the last found element.void
rightClick
(int wait) Right click on the last found element.void
rightClick
(State state) Right click on the last found element.void
rightClickAt
(int x, int y) Right click at the coordinate defined by x and y.void
rightClickAt
(int x, int y, int clicks) Right click at the coordinate defined by x and y.void
rightClickRelative
(int x, int y) Right Click Relative on the last found element.saveScreenshot
(String output) Saves a screenshot in a given path.org.marvinproject.framework.image.MarvinImage
Capture a screenshot from a region of the screen.org.marvinproject.framework.image.MarvinImage
screenshot
(String output) Capture a screenshot.void
scrollDown
(int clicks) Scroll Down n clicks.void
scrollElement
(org.openqa.selenium.WebElement element) Scrolls down an element by its scroll height or a given amount defined by `start` and `end`.void
scrollElement
(org.openqa.selenium.WebElement element, int steps, int interval, int start, int end) Scrolls down an element by its scroll height or a given amount defined by `start` and `end`.void
scrollUp
(int clicks) Scroll Up n clicks.void
setCurrentElement
(State state) Changes the current screen element the bot will interact when using click(), move(), and similar methods.void
setDownloadPath
(String path) void
setDriverPath
(String path) void
setFileInputElement
(org.openqa.selenium.WebElement element, File filePath) Configure the filepath for upload in a file element.void
setScreenResolution
(int width, int height) Configures the browser dimensions.void
sleep
(int ms) Wait / Sleep for a given interval.void
space()
Press key Space.void
space
(int wait) Press key Space.void
Starts the selected browser.void
Stops the Chrome browser and clean up the User Data Directory.void
tab()
Press key Tab.void
tab
(int wait) Press key Tab.void
Triple Click on the last found element.void
tripleClick
(int wait) Triple Click on the last found element.void
tripleClickRelative
(int x, int y) Triple Click Relative on the last found element.void
Type a text char by char (individual key events).void
Type a text char by char (individual key events).void
typeDown()
Press Down keyvoid
typeDown
(int wait) Press Down keyvoid
typeKeys
(CharSequence... keys) Press a sequence of keys.void
typeLeft()
Press Left key.void
typeLeft
(int wait) Press Left key.void
Press Right key.void
typeRight
(int wait) Press Right key.void
typeUp()
Press Up keyvoid
typeUp
(int wait) Press Up keyvoid
wait
(int ms) Wait / Sleep for a given interval.boolean
waitForDownloads
(int timeout) Wait for all downloads to be finished.boolean
waitForElementVisibilitiy
(org.openqa.selenium.WebElement element, boolean visible, long waitingTime) Wait for the element to be visible or hidden.boolean
waitForElementVisibilitiy
(org.openqa.selenium.WebElement element, long waitingTime) Wait for the element to be visible or hidden.boolean
waitForFile
(String path, long timeout) Wait for a file to be available on disk.waitForNewFile
(String path, String fileExtension, int currentCount, long timeout) Wait for a new file to be available on disk without the file path.void
waitForNewPage
(boolean activate, long waitingTime, Runnable function) Context manager to wait for a new page to load and activate it.void
waitForNewPage
(boolean activate, Runnable function) Context manager to wait for a new page to load and activate it.void
waitForNewPage
(Runnable function) Context manager to wait for a new page to load and activate it.boolean
waitForStaleElement
(org.openqa.selenium.WebElement element, long waitingTime) Wait until the WebElement element becomes stale (outdated).
-
Constructor Details
-
WebBot
public WebBot()
-
-
Method Details
-
setDriverPath
-
setDownloadPath
-
startBrowser
public void startBrowser()Starts the selected browser. -
stopBrowser
public void stopBrowser()Stops the Chrome browser and clean up the User Data Directory.Warning:
After invoking this method, you will need to reassign your custom options and capabilities.
-
getDriver
public org.openqa.selenium.WebDriver getDriver()The WebDriver driver instance.- Returns:
- The
WebDriver
driver instance
-
setScreenResolution
public void setScreenResolution(int width, int height) Configures the browser dimensions.- Parameters:
width
- The desired width.height
- The desired height.
-
maximizeWindow
public void maximizeWindow()Shortcut to maximize window on Windows OS. -
getScreenImage
Capture and returns a screenshot from the browser.- Parameters:
region
- aRegion
instance with the left, top, width and height to crop the screen image.- Returns:
- The screenshot
MarvinImage
object.
-
getScreenImage
public org.marvinproject.framework.image.MarvinImage getScreenImage()Capture and returns a screenshot from the browser.- Returns:
- The screenshot
MarvinImage
object.
-
getScreenshot
public org.marvinproject.framework.image.MarvinImage getScreenshot()Capture a screenshot.- Returns:
- The screenshot
MarvinImage
object.
-
saveScreenshot
Saves a screenshot in a given path.- Parameters:
output
- the filepath in which to save the screenshot.- Returns:
- The filepath in which to save the screenshot.
-
screenshot
Capture a screenshot.- Parameters:
output
- the filepath in which to save the screenshot.- Returns:
- The screenshot
MarvinImage
object.
-
screenCut
Capture a screenshot from a region of the screen.- Parameters:
region
- aRegion
instance with the left, top, width and height.- Returns:
- The screenshot
MarvinImage
object.
-
getPageSize
public org.openqa.selenium.Dimension getPageSize()Returns the browser current page size.- Returns:
- The
Dimension
instance with page size.
-
displaySize
public org.openqa.selenium.Dimension displaySize()Returns the display size in pixels.- Returns:
- The
Dimension
instance with display size.
-
getViewportSize
public org.openqa.selenium.Dimension getViewportSize()Returns the browser current viewport size.- Returns:
- The
Dimension
instance with viewport size.
-
browse
Opens the browser on the given URL.- Parameters:
url
- The URL to be visited.
-
getTabs
Get a list of tab handlers.- Returns:
- List of tab handlers.
-
activateTab
Activate a tab given by the handle.- Parameters:
handle
- The tab or window handle.
-
createTab
Create a new tab and navigate to the given URL.- Parameters:
url
- The desired URL.
-
createWindow
Creates a new window with the given URL.- Parameters:
url
- The desired URL.
-
closePage
public void closePage()Close the current active page (tab or window). -
pageTitle
Returns the active page title.- Returns:
- The page title.
-
pageSource
public org.jsoup.nodes.Document pageSource()Returns the active page source.- Returns:
Document
object for the page source.
-
executeJavascript
Execute the given javascript code.- Parameters:
code
- The code to be executed.args
- The arguments to be passed to the code.- Returns:
- Returns the code output.
-
enterIframe
public void enterIframe(org.openqa.selenium.WebElement element) Switch the WebBot driver to the specified iframe.- Parameters:
element
- The iframe element.
-
leaveIframe
public void leaveIframe()Leave the iframe and switch the WebBot driver to the default content. -
getFileCount
Get the total number of files of the same type.- Parameters:
path
- The path of the folder where the files are saved.fileExtension
- The extension of the files to be searched for (e.g., .pdf, .txt).- Returns:
- The number of files of the given type.
-
back
public void back()Pressing the browser’s back button. -
forward
public void forward()Pressing the browser’s forward button. -
refresh
public void refresh()Refresh the current page. -
findElement
public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by, boolean ensureVisible, boolean ensureClickable, long waitingTime) Find an element using the specified selector with selector type specified by `by`. If more than one element is found, the first instance is returned.- Parameters:
by
- The selector type with the selector string.ensureVisible
- True to wait for the element to be visible.ensureClickable
- True to wait for the element to be clickable.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- The
WebElement
found.
-
findElement
public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by) Find an element using the specified selector with selector type specified by `by`. If more than one element is found, the first instance is returned.- Parameters:
by
- The selector type with the selector string.- Returns:
- The
WebElement
found.
-
findElements
public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by, boolean ensureVisible, long waitingTime) Find elements using the specified selector with selector type specified by `by`.- Parameters:
by
- The selector type with the selector string.ensureVisible
- True to wait for the element to be visible.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- The list of
WebElement
found.
-
findElements
Find elements using the specified selector with selector type specified by `by`.- Parameters:
by
- The selector type with the selector string.- Returns:
- The list of
WebElement
found.
-
getJsDialog
public org.openqa.selenium.Alert getJsDialog()Return the last found dialog. Invoke first the `find_js_dialog` method to look up.- Returns:
- A handle to the dialog.
-
handleJsDialog
Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload). This also cleans the dialog information in the local buffer.- Parameters:
accept
- Whether to accept or dismiss the dialog.promptText
- The text to enter into the dialog prompt before accepting. Used only if this is a prompt dialog.- Returns:
- True if the dialog was handled successfully.
-
handleJsDialog
public boolean handleJsDialog(boolean accept) Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).- Parameters:
accept
- Whether to accept or dismiss the dialog.- Returns:
- True if the dialog was handled successfully.
-
waitForDownloads
public boolean waitForDownloads(int timeout) Wait for all downloads to be finished. Beware that this method replaces the current page with the downloads window.- Parameters:
timeout
- Timeout in millis.- Returns:
- True if the downloads window was found and all downloads finished. False if the timeout was reached.
-
waitForFile
Wait for a file to be available on disk.- Parameters:
path
- The path for the file to be executed.timeout
- Maximum wait time (ms) to search for a hit.- Returns:
- True if the file was found. False if the timeout was reached.
-
waitForNewFile
Wait for a new file to be available on disk without the file path.- Parameters:
path
- The path of the folder where the file is expected.fileExtension
- The extension of the file to be searched for (e.g., .pdf, .txt).currentCount
- The current number of files in the folder of the given type.timeout
- Maximum wait time (ms) to search for a hit.- Returns:
- The path of the last created file of the given type.
-
waitForNewPage
Context manager to wait for a new page to load and activate it.- Parameters:
activate
- Whether or not to activate the new page.waitingTime
- The maximum waiting time. Defaults to 10000.function
- The lambda function to be executed.
-
waitForNewPage
Context manager to wait for a new page to load and activate it.- Parameters:
activate
- Whether or not to activate the new page.function
- The lambda function to be executed.
-
waitForNewPage
Context manager to wait for a new page to load and activate it.- Parameters:
function
- The lambda function to be executed.
-
waitForElementVisibilitiy
public boolean waitForElementVisibilitiy(org.openqa.selenium.WebElement element, boolean visible, long waitingTime) Wait for the element to be visible or hidden.- Parameters:
element
- The element to wait for.visible
- Whether to wait for the element to be visible.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- True if the element is visible. False if the timeout was reached.
-
waitForElementVisibilitiy
public boolean waitForElementVisibilitiy(org.openqa.selenium.WebElement element, long waitingTime) Wait for the element to be visible or hidden.- Parameters:
element
- The element to wait for.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- True if the element is visible. False if the timeout was reached.
-
waitForStaleElement
public boolean waitForStaleElement(org.openqa.selenium.WebElement element, long waitingTime) Wait until the WebElement element becomes stale (outdated).- Parameters:
element
- The element to monitor for staleness.waitingTime
- Timeout in millis.- Returns:
- True if the element is stale. False if the timeout was reached.
-
scrollElement
public void scrollElement(org.openqa.selenium.WebElement element, int steps, int interval, int start, int end) Scrolls down an element by its scroll height or a given amount defined by `start` and `end`.This is useful for scrolling down a page to load more content or to scroll down a dynamically loaded element.
- Parameters:
element
- The element to scroll.steps
- Number of steps in which to conclude the scroll.interval
- Time interval between each step.start
- Start position.end
- End position.
-
scrollElement
public void scrollElement(org.openqa.selenium.WebElement element) Scrolls down an element by its scroll height or a given amount defined by `start` and `end`.This is useful for scrolling down a page to load more content or to scroll down a dynamically loaded element.
- Parameters:
element
- The element to scroll.
-
printPdf
Print the current page as a PDF file.- Parameters:
path
- The path for the file to be saved.printOptions
- Print options as defined at.- Returns:
- The saved file path.
-
printPdf
Print the current page as a PDF file.- Parameters:
path
- The path for the file to be saved.- Returns:
- The saved file path.
-
printPdf
Print the current page as a PDF file.- Returns:
- The saved file path.
-
installFirefoxExtension
Install an extension in the Firefox browser. This will start the browser if it was not started yet.- Parameters:
extensionPath
- The path of the .xpi extension to be loaded.
-
setFileInputElement
Configure the filepath for upload in a file element. Note: This method does not submit the form.- Parameters:
element
- The file upload element.filePath
- The path to the file to be uploaded.
-
pageDown
public void pageDown(int wait) Press Page Down key.- Parameters:
wait
- Wait interval (ms) after task.
-
pageDown
public void pageDown()Press Page Down key -
pageUp
public void pageUp(int wait) Press Page Up key.- Parameters:
wait
- Wait interval (ms) after task.
-
pageUp
public void pageUp()Press Page Up key -
enter
public void enter(int wait) -
enter
public void enter()Press key Enter. -
type
Type a text char by char (individual key events).- Parameters:
text
- Text to be typed.interval
- Interval (ms) between each key press.
-
type
Type a text char by char (individual key events).- Parameters:
text
- Text to be typed.
-
kbType
Type a text char by char (individual key events).- Parameters:
text
- Text to be typed.
-
paste
public void paste()Paste content from the clipboard. -
controlC
public void controlC(int wait) Press keys CTRL+C.- Parameters:
wait
- Wait interval (ms) after task.
-
controlC
public void controlC()Press keys CTRL+C. -
controlA
public void controlA(int wait) Press keys CTRL+A.- Parameters:
wait
- Wait interval (ms) after task.
-
controlA
public void controlA()Press keys CTRL+A. -
controlV
public void controlV()Press keys CTRL+X. -
keyEsc
public void keyEsc(int wait) Press key Esc.- Parameters:
wait
- Wait interval (ms) after task.
-
keyEsc
public void keyEsc()Press key Esc. -
keyEnter
public void keyEnter(int wait) Press key Enter.- Parameters:
wait
- Wait interval (ms) after task.
-
keyEnter
public void keyEnter()Press key Enter. -
keyHome
public void keyHome(int wait) Press key Home.- Parameters:
wait
- Wait interval (ms) after task.
-
keyHome
public void keyHome()Press key Home. -
keyEnd
public void keyEnd(int wait) Press key End.- Parameters:
wait
- Wait interval (ms) after task.
-
keyEnd
public void keyEnd()Press key End. -
delete
public void delete(int wait) Press key Delete.- Parameters:
wait
- Wait interval (ms) after task.
-
delete
public void delete()Press key Delete. -
space
public void space(int wait) Press key Space.- Parameters:
wait
- Wait interval (ms) after task.
-
space
public void space()Press key Space. -
tab
public void tab(int wait) Press key Tab.- Parameters:
wait
- Wait interval (ms) after task.
-
tab
public void tab()Press key Tab. -
typeKeys
Press a sequence of keys. Hold the keys in the specific order and releases them.- Parameters:
keys
- List of Keys to be pressed.
-
typeLeft
public void typeLeft(int wait) Press Left key.- Parameters:
wait
- Wait interval (ms) after task.
-
typeLeft
public void typeLeft()Press Left key. -
typeRight
public void typeRight(int wait) Press Right key.- Parameters:
wait
- Wait interval (ms) after task.
-
typeRight
public void typeRight()Press Right key. -
typeDown
public void typeDown(int wait) Press Down key- Parameters:
wait
- Wait interval (ms) after task.
-
typeDown
public void typeDown()Press Down key -
typeUp
public void typeUp(int wait) Press Up key- Parameters:
wait
- Wait interval (ms) after task.
-
typeUp
public void typeUp()Press Up key -
keyRight
public void keyRight(int wait) Press key Right.- Parameters:
wait
- Wait interval (ms) after task.
-
backspace
public void backspace(int wait) Press Backspace key.- Parameters:
wait
- Wait interval (ms) after task.
-
backspace
public void backspace()Press Backspace key. -
holdShift
public void holdShift(int wait) Hold key Shift.- Parameters:
wait
- Wait interval (ms) after task.
-
holdShift
public void holdShift()Hold key Shift. -
releaseShift
public void releaseShift()Release key Shift. This method needs to be invoked after holding Shift or similar. -
copyToClipboard
Copy content to the clipboard.- Parameters:
text
- The text to be copied.
-
getClipboard
Get the current content in the clipboard.- Returns:
- Current clipboard content.
-
wait
public void wait(int ms) Wait / Sleep for a given interval.- Parameters:
ms
- The interval (ms) to wait.
-
sleep
public void sleep(int ms) Wait / Sleep for a given interval.- Parameters:
ms
- The interval (ms) to wait.
-
addImage
Add an image into the state image map.- Parameters:
label
- The image identifier.path
- The path for the image on disk.
-
setCurrentElement
Changes the current screen element the bot will interact when using click(), move(), and similar methods.- Parameters:
state
- A screen element coordinates (left, top, width, height).
-
getLastElement
Return the last element found.- Returns:
- The element coordinates (left, top, width, height)
-
getLastX
public int getLastX()Return the x position of the last element found.- Returns:
- The x position.
-
getLastY
public int getLastY()Return the y position of the last element found.- Returns:
- The y position.
-
getElementCoords
Find an element defined by label on screen and returns its coordinates.- Parameters:
label
- The image identifier.region
- The region to search.matching
- Minimum score to consider a match in the element image recognition process.- Returns:
- A
State
instance with the x and y coordinates for the element.
-
getElementCoords
Find an element defined by label on screen and returns its coordinates.- Parameters:
label
- The image identifier.matching
- Minimum score to consider a match in the element image recognition process.- Returns:
- A
State
instance with the x and y coordinates for the element.
-
getElementCoordsCentered
Find an element defined by label on screen and returns its centered coordinates.- Parameters:
label
- The image identifier.matching
- Minimum score to consider a match in the element image recognition process.- Returns:
- Point with coordinates of the center of the element.
-
findUntil
public boolean findUntil(org.marvinproject.framework.image.MarvinImage visualElem, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find an element defined by label on screen until a timeout happens.- Parameters:
visualElem
- The image to be found.region
- The region to search.threshold
- The threshold to be applied when doing grayscale search.grayscale
- Whether or not to convert to grayscale before searching.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.best
- Whether or not to keep looking until the best matching is found.- Returns:
- True if element was found, false otherwise.
-
findUntil
public boolean findUntil(String label, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find an element defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.region
- The region to search.threshold
- The threshold to be applied when doing grayscale search.grayscale
- Whether or not to convert to grayscale before searching.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.best
- Whether or not to keep looking until the best matching is found.- Returns:
- True if element was found, false otherwise.
-
findUntil
public boolean findUntil(String label, int threshold, boolean grayscale, double matching, long waitingTime) Find an element defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.threshold
- The threshold to be applied when doing grayscale search.grayscale
- Whether or not to convert to grayscale before searching.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- True if element was found, false otherwise.
-
findUntil
public boolean findUntil(org.marvinproject.framework.image.MarvinImage visualImage, int threshold, boolean grayscale, double matching) Find an element defined by label on screen until a timeout happens.- Parameters:
visualImage
- The image to be found.threshold
- The threshold to be applied when doing grayscale search.grayscale
- Whether or not to convert to grayscale before searching.matching
- The matching index ranging from 0 to 1.- Returns:
- True if element was found, false otherwise.
-
findText
Find an element defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.threshold
- The threshold to be applied when doing grayscale search.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- True if element was found, false otherwise.
-
findText
Find an element defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- True if element was found, false otherwise.
-
find
public boolean find(String label, double matching, int threshold, boolean grayscale, long waitingTime) Find an element defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.matching
- The matching index ranging from 0 to 1.threshold
- The threshold to be applied when doing grayscale search.grayscale
- Whether or not to convert to grayscale before searching.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- True if element was found, false otherwise.
-
find
Find an element defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.matching
- The matching index ranging from 0 to 1.grayscale
- Whether or not to convert to grayscale before searching.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- True if element was found, false otherwise.
-
find
Find an element defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- True if element was found, false otherwise.
-
findAll
public List<State> findAll(org.marvinproject.framework.image.MarvinImage visualElem, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find all elements defined by label on screen until a timeout happens.- Parameters:
visualElem
- TheMarvinImage
to find.region
- The region to search for the elements.threshold
- The threshold to be applied when doing grayscale search.grayscale
- Whether or not to convert to grayscale before searching.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.best
- Whether or not to keep looking until the best matching is found.- Returns:
- A list with all element coordinates found.
-
findAll
public List<State> findAll(String label, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find all elements defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.region
- The region to search for the elements.threshold
- The threshold to be applied when doing grayscale search.grayscale
- Whether or not to convert to grayscale before searching.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.best
- Whether or not to keep looking until the best matching is found.- Returns:
- A list with all element coordinates found.
-
findAll
Find all elements defined by label on screen until a timeout happens.- Parameters:
label
- The image identifier.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- A list with all element coordinates found.
-
findMultiple
public Map<String,State> findMultiple(List<String> labels, Region region, int threshold, boolean grayscale, double matching, long waitingTime, boolean best) Find multiple elements defined by label on screen until a timeout happens.- Parameters:
labels
- A list of image identifiers.region
- The region to search for the elements.threshold
- The threshold to be applied when doing grayscale search.grayscale
- Whether or not to convert to grayscale before searching.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.best
- Whether or not to keep looking until the best matching is found.- Returns:
- A Map in which the key is the label and value are the element coordinates.
-
findMultiple
Find multiple elements defined by label on screen until a timeout happens.- Parameters:
labels
- A list of image identifiers.matching
- The matching index ranging from 0 to 1.waitingTime
- Maximum wait time (ms) to search for a hit.- Returns:
- A Map in which the key is the label and value are the element coordinates.
-
clickAt
Click at the coordinate defined by x and y.- Parameters:
x
- The X coordinate.y
- The Y coordinate.clicks
- Number of times to click.intervalBetweenClicks
- The interval between clicks in ms.button
- One of 'left', 'right'.
-
clickAt
public void clickAt(int x, int y, int clicks) Click at the coordinate defined by x and y.- Parameters:
x
- The X coordinate.y
- The Y coordinate.clicks
- The number of clicks.
-
clickAt
public void clickAt(int x, int y) Click at the coordinate defined by x and y.- Parameters:
x
- The X coordinate.y
- The Y coordinate.
-
clickOn
Click on the element.- Parameters:
label
- The image identifiermatching
- The matching index ranging from 0 to 1.
-
clickOn
Click on the element.- Parameters:
label
- The image identifier.
-
rightClickAt
public void rightClickAt(int x, int y, int clicks) Right click at the coordinate defined by x and y.- Parameters:
x
- The X coordinate.y
- The Y coordinate.clicks
- The number of clicks.
-
rightClickAt
public void rightClickAt(int x, int y) Right click at the coordinate defined by x and y.- Parameters:
x
- The X coordinate.y
- The Y coordinate.
-
click
Click on the last found element.- Parameters:
clicks
- Number of times to click.intervalBetweenClicks
- The interval between clicks in ms.button
- One of 'left', 'right'.wait
- Interval to wait after clicking on the element.
-
click
Left click on the last found element.- Parameters:
state
- The element to be clicked.
-
click
public void click(int wait) Click on the last found element.- Parameters:
wait
- Interval to wait after clicking on the element.
-
click
public void click()Click on the last found element. -
clickRelative
public void clickRelative(int x, int y) Click Relative on the last found element.- Parameters:
x
- Horizontal offset.y
- Vertical offset.
-
doubleClickRelative
public void doubleClickRelative(int x, int y) Double Click Relative on the last found element.- Parameters:
x
- Horizontal offset.y
- Vertical offset.
-
doubleClick
public void doubleClick(int wait) Double Click on the last found element.- Parameters:
wait
- Interval to wait after clicking on the element.
-
doubleClick
public void doubleClick()Double Click on the last found element. -
tripleClick
public void tripleClick(int wait) Triple Click on the last found element.- Parameters:
wait
- Interval to wait after clicking on the element.
-
tripleClick
public void tripleClick()Triple Click on the last found element. -
tripleClickRelative
public void tripleClickRelative(int x, int y) Triple Click Relative on the last found element.- Parameters:
x
- Horizontal offset.y
- Vertical offset.
-
rightClick
Right click on the last found element.- Parameters:
state
- The element to be clicked.
-
rightClick
public void rightClick(int wait) Right click on the last found element.- Parameters:
wait
- Interval to wait after clicking on the element.
-
rightClick
public void rightClick()Right click on the last found element. -
rightClickRelative
public void rightClickRelative(int x, int y) Right Click Relative on the last found element.- Parameters:
x
- Horizontal offset.y
- Vertical offset.
-
moveTo
public void moveTo(int x, int y, int wait) Move the mouse relative to its current position.- Parameters:
x
- The X coordinate.y
- The Y coordinate.wait
- Interval to wait after moving on the element.
-
moveTo
public void moveTo(int x, int y) Move the mouse relative to its current position.- Parameters:
x
- The X coordinate.y
- The Y coordinate.
-
mouseMove
public void mouseMove(int x, int y) Mouse the move to the coordinate defined by x and y.- Parameters:
x
- The X coordinate.y
- The Y coordinate.
-
moveRelative
public void moveRelative(int x, int y) Move the mouse relative to its current position.- Parameters:
x
- Horizontal offset.y
- Vertical offset.
-
move
public void move(int wait) Move to the center position of last found item.- Parameters:
wait
- Interval to wait after moving on the element.
-
move
public void move()Move to the center position of last found item. -
moveRandom
public void moveRandom(int rangeX, int rangeY) Move randomly along the given x, y range.- Parameters:
rangeX
- Horizontal range.rangeY
- Vertical range.
-
mouseDown
public void mouseDown(int wait) Holds down the requested mouse button.- Parameters:
wait
- Interval to wait after clicking on the element.
-
mouseDown
public void mouseDown()Holds down the requested mouse button. -
mouseUp
public void mouseUp(int wait) Releases the requested mouse button.- Parameters:
wait
- Interval to wait after clicking on the element.
-
mouseUp
public void mouseUp()Releases the requested mouse button. -
scrollDown
public void scrollDown(int clicks) Scroll Down n clicks.- Parameters:
clicks
- Number of times to scroll down.
-
scrollUp
public void scrollUp(int clicks) Scroll Up n clicks.- Parameters:
clicks
- Number of times to scroll up.
-