Package ai.devtools.selenium
Class SmartDriver
java.lang.Object
org.openqa.selenium.remote.RemoteWebDriver
ai.devtools.selenium.SmartDriver
- All Implemented Interfaces:
HasCapabilities,HasInputDevices,Interactive,FindsByClassName,FindsByCssSelector,FindsById,FindsByLinkText,FindsByName,FindsByTagName,FindsByXPath,JavascriptExecutor,SearchContext,TakesScreenshot,WebDriver
The
SmartDriver class is a wrapper around a RemoteWebDriver that uses the results of the dev-tools.ai classifier for improved robustness, finding elements visually and avoiding broken selectors.-
Nested Class Summary
Nested classes/interfaces inherited from class org.openqa.selenium.remote.RemoteWebDriver
RemoteWebDriver.WhenNested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
WebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window -
Field Summary
FieldsModifier and TypeFieldDescriptionThe driver used by the user that we're wrapping.doubleThe screen density multiplier -
Constructor Summary
ConstructorsConstructorDescriptionSmartDriver(RemoteWebDriver driver, String apiKey) Constructor, creates a new SmartDriver with the default server url (smartdriver.dev-tools.ai), non-interactive mode, and with training enabled.SmartDriver(RemoteWebDriver driver, String apiKey, Map<String, Object> initializationDict) Constructor, creates a new SmartDriver. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()executeAsyncScript(String script, Object... args) executeScript(String script, Object... args) Finds an elements byelementName.findByElementName(String elementName) Finds an element byelementName.findElement(By locator) findElement(By locator, String elementName) findElementByClassName(String using) Attempts to find an element by class name.findElementByClassName(String using, String elementName) Attempts to find an element by class name.findElementByCssSelector(String using) Attempts to find an element by css selector.findElementByCssSelector(String using, String elementName) Attempts to find an element by css selector.findElementByElementName(String elementName) Finds an element byelementName.findElementById(String using) Attempts to find an element by id.findElementById(String using, String elementName) Attempts to find an element by id.findElementByLinkText(String using) Attempts to find an element by link text.findElementByLinkText(String using, String elementName) Attempts to find an element by link text.findElementByName(String using) Attempts to find an element by name.findElementByName(String using, String elementName) Attempts to find an element by name.Attempts to find an element by partial link text.findElementByPartialLinkText(String using, String elementName) Attempts to find an element by partial link text.findElementByTagName(String using) Attempts to find an element by tag name.findElementByTagName(String using, String elementName) Attempts to find an element by tag name.findElementByXPath(String using) Attempts to find an element by xpath.findElementByXPath(String using, String elementName) Attempts to find an element by xpath.findElements(By locator) findElementsByClassName(String using) Attempts to find all elements with the matching class name.findElementsByCssSelector(String using) Attempts to find all elements with the matching css selector.findElementsById(String using) Attempts to find all elements with the matching id.findElementsByLinkText(String using) Attempts to find all elements with the matching link text.findElementsByName(String using) Attempts to find all elements with the matching name.Attempts to find all elements with the matching partial link text.findElementsByTagName(String using) Attempts to find all elements with the matching tag name.findElementsByXPath(String using) Attempts to find all elements with the matching xpath.voidOpens a web browser and directs it tourl.<X> XgetScreenshotAs(OutputType<X> outputType) getTitle()implicitlyWait(long waitTime) Convenience method, implicitly wait for the specified amount of time.manage()navigate()voidperform(Collection<Sequence> actions) voidquit()voidvoidscrollPage(int amount) voidscrollToElement(WebElement element, Boolean scrollUp) voidsetErrorHandler(ErrorHandler handler) voidsetFileDetector(FileDetector detector) voidsetLogLevel(Level level) switchTo()toString()Methods inherited from class org.openqa.selenium.remote.RemoteWebDriver
builder, getKeyboard, getMouse
-
Field Details
-
driver
The driver used by the user that we're wrapping. -
multiplier
public double multiplierThe screen density multiplier
-
-
Constructor Details
-
SmartDriver
public SmartDriver(RemoteWebDriver driver, String apiKey, Map<String, Object> initializationDict) throws IOExceptionConstructor, creates a new SmartDriver.- Parameters:
driver- TheRemoteWebDriverto wrapapiKey- Your API key, acquired from smartdriver.dev-tools.ai.initializationDict- The configuration options for the driver.- Throws:
IOException- If there was an initialization error.
-
SmartDriver
Constructor, creates a new SmartDriver with the default server url (smartdriver.dev-tools.ai), non-interactive mode, and with training enabled.- Parameters:
driver- TheRemoteWebDriverto wrapapiKey- Your API key, acquired from smartdriver.dev-tools.ai.- Throws:
IOException- If there was an initialization error.
-
-
Method Details
-
implicitlyWait
Convenience method, implicitly wait for the specified amount of time.- Parameters:
waitTime- The number of seconds to implicitly wait.- Returns:
- This
SmartDriver, for chaining convenience.
-
executeAsyncScript
- Specified by:
executeAsyncScriptin interfaceJavascriptExecutor- Overrides:
executeAsyncScriptin classRemoteWebDriver
-
executeScript
- Specified by:
executeScriptin interfaceJavascriptExecutor- Overrides:
executeScriptin classRemoteWebDriver
-
get
Opens a web browser and directs it tourl.- Specified by:
getin interfaceWebDriver- Overrides:
getin classRemoteWebDriver- Parameters:
url- The URL to launch the browser to.
-
findElement
-
findElement
- Specified by:
findElementin interfaceSearchContext- Specified by:
findElementin interfaceWebDriver- Overrides:
findElementin classRemoteWebDriver
-
findElements
- Specified by:
findElementsin interfaceSearchContext- Specified by:
findElementsin interfaceWebDriver- Overrides:
findElementsin classRemoteWebDriver
-
getCapabilities
- Specified by:
getCapabilitiesin interfaceHasCapabilities- Overrides:
getCapabilitiesin classRemoteWebDriver
-
getCommandExecutor
- Overrides:
getCommandExecutorin classRemoteWebDriver
-
getCurrentUrl
- Specified by:
getCurrentUrlin interfaceWebDriver- Overrides:
getCurrentUrlin classRemoteWebDriver
-
getErrorHandler
- Overrides:
getErrorHandlerin classRemoteWebDriver
-
getFileDetector
- Overrides:
getFileDetectorin classRemoteWebDriver
-
getPageSource
- Specified by:
getPageSourcein interfaceWebDriver- Overrides:
getPageSourcein classRemoteWebDriver
-
getScreenshotAs
- Specified by:
getScreenshotAsin interfaceTakesScreenshot- Overrides:
getScreenshotAsin classRemoteWebDriver
-
getSessionId
- Overrides:
getSessionIdin classRemoteWebDriver
-
getTitle
- Specified by:
getTitlein interfaceWebDriver- Overrides:
getTitlein classRemoteWebDriver
-
getWindowHandle
- Specified by:
getWindowHandlein interfaceWebDriver- Overrides:
getWindowHandlein classRemoteWebDriver
-
getWindowHandles
- Specified by:
getWindowHandlesin interfaceWebDriver- Overrides:
getWindowHandlesin classRemoteWebDriver
-
manage
- Specified by:
managein interfaceWebDriver- Overrides:
managein classRemoteWebDriver
-
perform
- Specified by:
performin interfaceInteractive- Overrides:
performin classRemoteWebDriver
-
quit
public void quit()- Specified by:
quitin interfaceWebDriver- Overrides:
quitin classRemoteWebDriver
-
resetInputState
public void resetInputState()- Specified by:
resetInputStatein interfaceInteractive- Overrides:
resetInputStatein classRemoteWebDriver
-
setErrorHandler
- Overrides:
setErrorHandlerin classRemoteWebDriver
-
setFileDetector
- Overrides:
setFileDetectorin classRemoteWebDriver
-
setLogLevel
- Overrides:
setLogLevelin classRemoteWebDriver
-
switchTo
- Specified by:
switchToin interfaceWebDriver- Overrides:
switchToin classRemoteWebDriver
-
toString
- Overrides:
toStringin classRemoteWebDriver
-
findElementByClassName
Attempts to find an element by class name.- Parameters:
using- The class name of the element to findelementName- The label name of the element to be classified. Optional, setnullto auto generate an element name.- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementByClassName
Attempts to find an element by class name.- Specified by:
findElementByClassNamein interfaceFindsByClassName- Overrides:
findElementByClassNamein classRemoteWebDriver- Parameters:
using- The class name of the element to find- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementsByClassName
Attempts to find all elements with the matching class name.- Specified by:
findElementsByClassNamein interfaceFindsByClassName- Overrides:
findElementsByClassNamein classRemoteWebDriver- Parameters:
using- The class name of the elements to find.- Returns:
- A
Listwith any elements that were found, or an emptyListif no matches were found.
-
findElementByCssSelector
Attempts to find an element by css selector.- Parameters:
using- The css selector of the element to findelementName- The label name of the element to be classified. Optional, setnullto auto generate an element name.- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementByCssSelector
Attempts to find an element by css selector.- Specified by:
findElementByCssSelectorin interfaceFindsByCssSelector- Overrides:
findElementByCssSelectorin classRemoteWebDriver- Parameters:
using- The css selector of the element to find- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementsByCssSelector
Attempts to find all elements with the matching css selector.- Specified by:
findElementsByCssSelectorin interfaceFindsByCssSelector- Overrides:
findElementsByCssSelectorin classRemoteWebDriver- Parameters:
using- The css selector of the elements to find.- Returns:
- A
Listwith any elements that were found, or an emptyListif no matches were found.
-
findElementById
Attempts to find an element by id.- Parameters:
using- The id of the element to findelementName- The label name of the element to be classified. Optional, setnullto auto generate an element name.- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementById
Attempts to find an element by id.- Specified by:
findElementByIdin interfaceFindsById- Overrides:
findElementByIdin classRemoteWebDriver- Parameters:
using- The id of the element to find- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementsById
Attempts to find all elements with the matching id.- Specified by:
findElementsByIdin interfaceFindsById- Overrides:
findElementsByIdin classRemoteWebDriver- Parameters:
using- The id of the elements to find.- Returns:
- A
Listwith any elements that were found, or an emptyListif no matches were found.
-
findElementByLinkText
Attempts to find an element by link text.- Parameters:
using- The link text of the element to findelementName- The label name of the element to be classified. Optional, setnullto auto generate an element name.- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementByLinkText
Attempts to find an element by link text.- Specified by:
findElementByLinkTextin interfaceFindsByLinkText- Overrides:
findElementByLinkTextin classRemoteWebDriver- Parameters:
using- The link text of the element to find- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementsByLinkText
Attempts to find all elements with the matching link text.- Specified by:
findElementsByLinkTextin interfaceFindsByLinkText- Overrides:
findElementsByLinkTextin classRemoteWebDriver- Parameters:
using- The link text of the elements to find.- Returns:
- A
Listwith any elements that were found, or an emptyListif no matches were found.
-
findElementByName
Attempts to find an element by name.- Parameters:
using- The name of the element to findelementName- The label name of the element to be classified. Optional, setnullto auto generate an element name.- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementByName
Attempts to find an element by name.- Specified by:
findElementByNamein interfaceFindsByName- Overrides:
findElementByNamein classRemoteWebDriver- Parameters:
using- The name of the element to find- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementsByName
Attempts to find all elements with the matching name.- Specified by:
findElementsByNamein interfaceFindsByName- Overrides:
findElementsByNamein classRemoteWebDriver- Parameters:
using- The name of the elements to find.- Returns:
- A
Listwith any elements that were found, or an emptyListif no matches were found.
-
findElementByPartialLinkText
Attempts to find an element by partial link text.- Parameters:
using- The partial link text of the element to findelementName- The label name of the element to be classified. Optional, setnullto auto generate an element name.- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementByPartialLinkText
Attempts to find an element by partial link text.- Specified by:
findElementByPartialLinkTextin interfaceFindsByLinkText- Overrides:
findElementByPartialLinkTextin classRemoteWebDriver- Parameters:
using- The partial link text of the element to find- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementsByPartialLinkText
Attempts to find all elements with the matching partial link text.- Specified by:
findElementsByPartialLinkTextin interfaceFindsByLinkText- Overrides:
findElementsByPartialLinkTextin classRemoteWebDriver- Parameters:
using- The partial link text of the elements to find.- Returns:
- A
Listwith any elements that were found, or an emptyListif no matches were found.
-
findElementByTagName
Attempts to find an element by tag name.- Parameters:
using- The tag name of the element to findelementName- The label name of the element to be classified. Optional, setnullto auto generate an element name.- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementByTagName
Attempts to find an element by tag name.- Specified by:
findElementByTagNamein interfaceFindsByTagName- Overrides:
findElementByTagNamein classRemoteWebDriver- Parameters:
using- The tag name of the element to find- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementsByTagName
Attempts to find all elements with the matching tag name.- Specified by:
findElementsByTagNamein interfaceFindsByTagName- Overrides:
findElementsByTagNamein classRemoteWebDriver- Parameters:
using- The tag name of the elements to find.- Returns:
- A
Listwith any elements that were found, or an emptyListif no matches were found.
-
findElementByXPath
Attempts to find an element by xpath.- Parameters:
using- The xpath of the element to findelementName- The label name of the element to be classified. Optional, setnullto auto generate an element name.- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementByXPath
Attempts to find an element by xpath.- Specified by:
findElementByXPathin interfaceFindsByXPath- Overrides:
findElementByXPathin classRemoteWebDriver- Parameters:
using- The xpath of the element to find- Returns:
- The element that was found. Raises an exception otherwise.
-
findElementsByXPath
Attempts to find all elements with the matching xpath.- Specified by:
findElementsByXPathin interfaceFindsByXPath- Overrides:
findElementsByXPathin classRemoteWebDriver- Parameters:
using- The xpath of the elements to find.- Returns:
- A
Listwith any elements that were found, or an emptyListif no matches were found.
-
findByElementName
Finds an element byelementName. Please usefindElementByElementName(String)instead.- Parameters:
elementName- The label name of the element to be classified.- Returns:
- An element associated with
elementName. Throws NoSuchElementException otherwise.
-
findElementByElementName
Finds an element byelementName.- Parameters:
elementName- The label name of the element to be classified.- Returns:
- An element associated with
elementName. Throws NoSuchElementException otherwise.
-
findByAI
Finds an elements byelementName. Uses visual AI to find the element.- Parameters:
elementName- The label name of the element to be classified.- Returns:
- An element associated with
elementName. Throws NoSuchElementException otherwise.
-
scrollToElement
-
scrollPage
public void scrollPage(int amount) -
close
public void close()- Specified by:
closein interfaceWebDriver- Overrides:
closein classRemoteWebDriver
-