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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateTab(String handle) Activate a tab given by the handle.voidAdd an image into the state image map.voidback()Pressing the browser’s back button.voidPress Backspace key.voidbackspace(int wait) Press Backspace key.voidOpens the browser on the given URL.voidclick()Click on the last found element.voidclick(int wait) Click on the last found element.voidClick on the last found element.voidLeft click on the last found element.voidclickAt(int x, int y) Click at the coordinate defined by x and y.voidclickAt(int x, int y, int clicks) Click at the coordinate defined by x and y.voidClick at the coordinate defined by x and y.voidClick on the element.voidClick on the element.voidclickRelative(int x, int y) Click Relative on the last found element.voidClose the current active page (tab or window).voidcontrolA()Press keys CTRL+A.voidcontrolA(int wait) Press keys CTRL+A.voidcontrolC()Press keys CTRL+C.voidcontrolC(int wait) Press keys CTRL+C.voidcontrolV()Press keys CTRL+X.voidcopyToClipboard(String text) Copy content to the clipboard.voidCreate a new tab and navigate to the given URL.voidcreateWindow(String url) Creates a new window with the given URL.voiddelete()Press key Delete.voiddelete(int wait) Press key Delete.org.openqa.selenium.DimensionReturns the display size in pixels.voidDouble Click on the last found element.voiddoubleClick(int wait) Double Click on the last found element.voiddoubleClickRelative(int x, int y) Double Click Relative on the last found element.voidenter()Press key Enter.voidenter(int wait) voidenterIframe(org.openqa.selenium.WebElement element) Switch the WebBot driver to the specified iframe.executeJavascript(String code, Object... args) Execute the given javascript code.booleanFind an element defined by label on screen until a timeout happens.booleanFind an element defined by label on screen until a timeout happens.booleanFind 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.WebElementfindElement(org.openqa.selenium.By by) Find an element using the specified selector with selector type specified by `by`.org.openqa.selenium.WebElementfindElement(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.booleanFind an element defined by label on screen until a timeout happens.booleanFind an element defined by label on screen until a timeout happens.booleanFind an element defined by label on screen until a timeout happens.booleanfindUntil(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.booleanfindUntil(org.marvinproject.framework.image.MarvinImage visualImage, int threshold, boolean grayscale, double matching) Find an element defined by label on screen until a timeout happens.booleanfindUntil(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.voidforward()Pressing the browser’s forward button.Get the current content in the clipboard.org.openqa.selenium.WebDriverThe 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.intgetFileCount(String path, String fileExtension) Get the total number of files of the same type.org.openqa.selenium.AlertReturn the last found dialog.Return the last element found.intgetLastX()Return the x position of the last element found.intgetLastY()Return the y position of the last element found.org.openqa.selenium.DimensionReturns the browser current page size.org.marvinproject.framework.image.MarvinImageCapture and returns a screenshot from the browser.org.marvinproject.framework.image.MarvinImagegetScreenImage(Region region) Capture and returns a screenshot from the browser.org.marvinproject.framework.image.MarvinImageCapture a screenshot.getTabs()Get a list of tab handlers.org.openqa.selenium.DimensionReturns the browser current viewport size.booleanhandleJsDialog(boolean accept) Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).booleanhandleJsDialog(boolean accept, String promptText) Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).voidHold key Shift.voidholdShift(int wait) Hold key Shift.voidinstallFirefoxExtension(String extensionPath) Install an extension in the Firefox browser.voidType a text char by char (individual key events).voidkeyEnd()Press key End.voidkeyEnd(int wait) Press key End.voidkeyEnter()Press key Enter.voidkeyEnter(int wait) Press key Enter.voidkeyEsc()Press key Esc.voidkeyEsc(int wait) Press key Esc.voidkeyHome()Press key Home.voidkeyHome(int wait) Press key Home.voidkeyRight(int wait) Press key Right.voidLeave the iframe and switch the WebBot driver to the default content.voidShortcut to maximize window on Windows OS.voidHolds down the requested mouse button.voidmouseDown(int wait) Holds down the requested mouse button.voidmouseMove(int x, int y) Mouse the move to the coordinate defined by x and y.voidmouseUp()Releases the requested mouse button.voidmouseUp(int wait) Releases the requested mouse button.voidmove()Move to the center position of last found item.voidmove(int wait) Move to the center position of last found item.voidmoveRandom(int rangeX, int rangeY) Move randomly along the given x, y range.voidmoveRelative(int x, int y) Move the mouse relative to its current position.voidmoveTo(int x, int y) Move the mouse relative to its current position.voidmoveTo(int x, int y, int wait) Move the mouse relative to its current position.voidnavigateTo(String url) Opens the browser on the given URL.voidpageDown()Press Page Down keyvoidpageDown(int wait) Press Page Down key.org.jsoup.nodes.DocumentReturns the active page source.Returns the active page title.voidpageUp()Press Page Up keyvoidpageUp(int wait) Press Page Up key.voidpaste()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.voidrefresh()Refresh the current page.voidRelease key Shift.voidRight click on the last found element.voidrightClick(int wait) Right click on the last found element.voidrightClick(State state) Right click on the last found element.voidrightClickAt(int x, int y) Right click at the coordinate defined by x and y.voidrightClickAt(int x, int y, int clicks) Right click at the coordinate defined by x and y.voidrightClickRelative(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.MarvinImageCapture a screenshot from a region of the screen.org.marvinproject.framework.image.MarvinImagescreenshot(String output) Capture a screenshot.voidscrollDown(int clicks) Scroll Down n clicks.voidscrollElement(org.openqa.selenium.WebElement element) Scrolls down an element by its scroll height or a given amount defined by `start` and `end`.voidscrollElement(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`.voidscrollUp(int clicks) Scroll Up n clicks.voidsetCurrentElement(State state) Changes the current screen element the bot will interact when using click(), move(), and similar methods.voidsetDownloadPath(String path) voidsetDriverPath(String path) voidsetFileInputElement(org.openqa.selenium.WebElement element, File filePath) Configure the filepath for upload in a file element.voidsetScreenResolution(int width, int height) Configures the browser dimensions.voidsleep(int ms) Wait / Sleep for a given interval.voidspace()Press key Space.voidspace(int wait) Press key Space.voidStarts the selected browser.voidStops the Chrome browser and clean up the User Data Directory.voidtab()Press key Tab.voidtab(int wait) Press key Tab.voidTriple Click on the last found element.voidtripleClick(int wait) Triple Click on the last found element.voidtripleClickRelative(int x, int y) Triple Click Relative on the last found element.voidType a text char by char (individual key events).voidType a text char by char (individual key events).voidtypeDown()Press Down keyvoidtypeDown(int wait) Press Down keyvoidtypeKeys(CharSequence... keys) Press a sequence of keys.voidtypeLeft()Press Left key.voidtypeLeft(int wait) Press Left key.voidPress Right key.voidtypeRight(int wait) Press Right key.voidtypeUp()Press Up keyvoidtypeUp(int wait) Press Up keyvoidwait(int ms) Wait / Sleep for a given interval.booleanwaitForDownloads(int timeout) Wait for all downloads to be finished.booleanwaitForElementVisibilitiy(org.openqa.selenium.WebElement element, boolean visible, long waitingTime) Wait for the element to be visible or hidden.booleanwaitForElementVisibilitiy(org.openqa.selenium.WebElement element, long waitingTime) Wait for the element to be visible or hidden.booleanwaitForFile(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.voidwaitForNewPage(boolean activate, long waitingTime, Runnable function) Context manager to wait for a new page to load and activate it.voidwaitForNewPage(boolean activate, Runnable function) Context manager to wait for a new page to load and activate it.voidwaitForNewPage(Runnable function) Context manager to wait for a new page to load and activate it.booleanwaitForStaleElement(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
WebDriverdriver 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- aRegioninstance with the left, top, width and height to crop the screen image.- Returns:
- The screenshot
MarvinImageobject.
-
getScreenImage
public org.marvinproject.framework.image.MarvinImage getScreenImage()Capture and returns a screenshot from the browser.- Returns:
- The screenshot
MarvinImageobject.
-
getScreenshot
public org.marvinproject.framework.image.MarvinImage getScreenshot()Capture a screenshot.- Returns:
- The screenshot
MarvinImageobject.
-
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
MarvinImageobject.
-
screenCut
Capture a screenshot from a region of the screen.- Parameters:
region- aRegioninstance with the left, top, width and height.- Returns:
- The screenshot
MarvinImageobject.
-
getPageSize
public org.openqa.selenium.Dimension getPageSize()Returns the browser current page size.- Returns:
- The
Dimensioninstance with page size.
-
displaySize
public org.openqa.selenium.Dimension displaySize()Returns the display size in pixels.- Returns:
- The
Dimensioninstance with display size.
-
getViewportSize
public org.openqa.selenium.Dimension getViewportSize()Returns the browser current viewport size.- Returns:
- The
Dimensioninstance 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:
Documentobject 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
WebElementfound.
-
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
WebElementfound.
-
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
WebElementfound.
-
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
WebElementfound.
-
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
Stateinstance 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
Stateinstance 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- TheMarvinImageto 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.
-