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
public class SmartDriver extends RemoteWebDriver
TheSmartDriverclass is a wrapper around aRemoteWebDriverthat 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.When
-
Nested classes/interfaces inherited from interface org.openqa.selenium.WebDriver
WebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window
-
-
Field Summary
Fields Modifier and Type Field Description RemoteWebDriverdriverThe driver used by the user that we're wrapping.doublemultiplierThe screen density multiplierbooleanUseJSChopper
-
Constructor Summary
Constructors Constructor Description SmartDriver(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ObjectexecuteAsyncScript(String script, Object... args)ObjectexecuteScript(String script, Object... args)WebElementfindByAI(String elementName)Finds an elements byelementName.WebElementfindByAI(String elementName, Float customAiThreshold)WebElementfindByElementName(String elementName)Finds an element byelementName.WebElementfindElement(By locator)WebElementfindElement(By locator, Float customAIThreshold)WebElementfindElement(By locator, String elementName)WebElementfindElement(By locator, String elementName, Float customAIThreshold)WebElementfindElementByAI(String elementName)WebElementfindElementByAI(String elementName, Float customAIThreshold)WebElementfindElementByClassName(String using)Attempts to find an element by class name.WebElementfindElementByClassName(String using, Float customAIThreshold)WebElementfindElementByClassName(String using, String elementName)Attempts to find an element by class name.WebElementfindElementByClassName(String using, String elementName, Float customAIThreshold)WebElementfindElementByCssSelector(String using)Attempts to find an element by css selector.WebElementfindElementByCssSelector(String using, Float customAIThreshold)WebElementfindElementByCssSelector(String using, String elementName)Attempts to find an element by css selector.WebElementfindElementByCssSelector(String using, String elementName, Float customAIThreshold)WebElementfindElementByElementName(String elementName)WebElementfindElementByElementName(String elementName, Float customAiThreshold)Finds an element byelementName.WebElementfindElementById(String using)Attempts to find an element by id.WebElementfindElementById(String using, Float customAIThreshold)WebElementfindElementById(String using, String elementName)Attempts to find an element by id.WebElementfindElementById(String using, String elementName, Float customAIThreshold)WebElementfindElementByLinkText(String using)Attempts to find an element by link text.WebElementfindElementByLinkText(String using, Float customAIThreshold)WebElementfindElementByLinkText(String using, String elementName)Attempts to find an element by link text.WebElementfindElementByLinkText(String using, String elementName, Float customAIThreshold)WebElementfindElementByName(String using)Attempts to find an element by name.WebElementfindElementByName(String using, Float customAIThreshold)WebElementfindElementByName(String using, String elementName)Attempts to find an element by name.WebElementfindElementByName(String using, String elementName, Float customAIThreshold)WebElementfindElementByPartialLinkText(String using)Attempts to find an element by partial link text.WebElementfindElementByPartialLinkText(String using, Float customAIThreshold)WebElementfindElementByPartialLinkText(String using, String elementName)Attempts to find an element by partial link text.WebElementfindElementByPartialLinkText(String using, String elementName, Float customAIThreshold)WebElementfindElementByTagName(String using)Attempts to find an element by tag name.WebElementfindElementByTagName(String using, Float customAIThreshold)WebElementfindElementByTagName(String using, String elementName)Attempts to find an element by tag name.WebElementfindElementByTagName(String using, String elementName, Float customAIThreshold)WebElementfindElementByXPath(String using)Attempts to find an element by xpath.WebElementfindElementByXPath(String using, Float customAiThreshold)WebElementfindElementByXPath(String using, String elementName)Attempts to find an element by xpath.WebElementfindElementByXPath(String using, String elementName, Float customAiThreshold)List<WebElement>findElements(By locator)List<WebElement>findElementsByAI(String elementName)List<WebElement>findElementsByAI(String elementName, Float customAIThreshold)List<WebElement>findElementsByClassName(String using)Attempts to find all elements with the matching class name.List<WebElement>findElementsByCssSelector(String using)Attempts to find all elements with the matching css selector.List<WebElement>findElementsById(String using)Attempts to find all elements with the matching id.List<WebElement>findElementsByLinkText(String using)Attempts to find all elements with the matching link text.List<WebElement>findElementsByName(String using)Attempts to find all elements with the matching name.List<WebElement>findElementsByPartialLinkText(String using)Attempts to find all elements with the matching partial link text.List<WebElement>findElementsByTagName(String using)Attempts to find all elements with the matching tag name.List<WebElement>findElementsByXPath(String using)Attempts to find all elements with the matching xpath.voidget(String url)Opens a web browser and directs it tourl.CapabilitiesgetCapabilities()CommandExecutorgetCommandExecutor()StringgetCurrentUrl()ErrorHandlergetErrorHandler()FileDetectorgetFileDetector()StringgetPageSource()<X> XgetScreenshotAs(OutputType<X> outputType)SessionIdgetSessionId()StringgetTitle()StringgetWindowHandle()Set<String>getWindowHandles()SmartDriverimplicitlyWait(long waitTime)Convenience method, implicitly wait for the specified amount of time.WebDriver.Optionsmanage()WebDriver.Navigationnavigate()voidperform(Collection<Sequence> actions)voidquit()voidresetInputState()voidscrollPage(int amount)voidscrollToElement(WebElement element, Boolean scrollUp)voidsetErrorHandler(ErrorHandler handler)voidsetFileDetector(FileDetector detector)voidsetLogLevel(Level level)WebDriver.TargetLocatorswitchTo()StringtoString()-
Methods inherited from class org.openqa.selenium.remote.RemoteWebDriver
builder, findElements, getKeyboard, getMouse
-
-
-
-
Field Detail
-
driver
public RemoteWebDriver driver
The driver used by the user that we're wrapping.
-
multiplier
public double multiplier
The screen density multiplier
-
UseJSChopper
public boolean UseJSChopper
-
-
Constructor Detail
-
SmartDriver
public SmartDriver(RemoteWebDriver driver, String apiKey, Map<String,Object> initializationDict) throws IOException
Constructor, 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
public SmartDriver(RemoteWebDriver driver, String apiKey) throws IOException
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 Detail
-
implicitlyWait
public SmartDriver implicitlyWait(long waitTime)
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
public Object executeAsyncScript(String script, Object... args)
- Specified by:
executeAsyncScriptin interfaceJavascriptExecutor- Overrides:
executeAsyncScriptin classRemoteWebDriver
-
executeScript
public Object executeScript(String script, Object... args)
- Specified by:
executeScriptin interfaceJavascriptExecutor- Overrides:
executeScriptin classRemoteWebDriver
-
get
public void get(String url)
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
public WebElement findElement(By locator, String elementName)
-
findElement
public WebElement findElement(By locator, Float customAIThreshold)
-
findElement
public WebElement findElement(By locator, String elementName, Float customAIThreshold)
-
findElement
public WebElement findElement(By locator)
- Specified by:
findElementin interfaceSearchContext- Specified by:
findElementin interfaceWebDriver- Overrides:
findElementin classRemoteWebDriver
-
findElements
public List<WebElement> findElements(By locator)
-
findElementsByAI
public List<WebElement> findElementsByAI(String elementName)
-
findElementsByAI
public List<WebElement> findElementsByAI(String elementName, Float customAIThreshold)
-
findElementByAI
public WebElement findElementByAI(String elementName)
-
findElementByAI
public WebElement findElementByAI(String elementName, Float customAIThreshold)
-
getCapabilities
public Capabilities getCapabilities()
- Specified by:
getCapabilitiesin interfaceHasCapabilities- Overrides:
getCapabilitiesin classRemoteWebDriver
-
getCommandExecutor
public CommandExecutor getCommandExecutor()
- Overrides:
getCommandExecutorin classRemoteWebDriver
-
getCurrentUrl
public String getCurrentUrl()
- Specified by:
getCurrentUrlin interfaceWebDriver- Overrides:
getCurrentUrlin classRemoteWebDriver
-
getErrorHandler
public ErrorHandler getErrorHandler()
- Overrides:
getErrorHandlerin classRemoteWebDriver
-
getFileDetector
public FileDetector getFileDetector()
- Overrides:
getFileDetectorin classRemoteWebDriver
-
getPageSource
public String getPageSource()
- Specified by:
getPageSourcein interfaceWebDriver- Overrides:
getPageSourcein classRemoteWebDriver
-
getScreenshotAs
public <X> X getScreenshotAs(OutputType<X> outputType)
- Specified by:
getScreenshotAsin interfaceTakesScreenshot- Overrides:
getScreenshotAsin classRemoteWebDriver
-
getSessionId
public SessionId getSessionId()
- Overrides:
getSessionIdin classRemoteWebDriver
-
getTitle
public String getTitle()
- Specified by:
getTitlein interfaceWebDriver- Overrides:
getTitlein classRemoteWebDriver
-
getWindowHandle
public String getWindowHandle()
- Specified by:
getWindowHandlein interfaceWebDriver- Overrides:
getWindowHandlein classRemoteWebDriver
-
getWindowHandles
public Set<String> getWindowHandles()
- Specified by:
getWindowHandlesin interfaceWebDriver- Overrides:
getWindowHandlesin classRemoteWebDriver
-
manage
public WebDriver.Options manage()
- Specified by:
managein interfaceWebDriver- Overrides:
managein classRemoteWebDriver
-
navigate
public WebDriver.Navigation navigate()
- Specified by:
navigatein interfaceWebDriver- Overrides:
navigatein classRemoteWebDriver
-
perform
public void perform(Collection<Sequence> actions)
- 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
public void setErrorHandler(ErrorHandler handler)
- Overrides:
setErrorHandlerin classRemoteWebDriver
-
setFileDetector
public void setFileDetector(FileDetector detector)
- Overrides:
setFileDetectorin classRemoteWebDriver
-
setLogLevel
public void setLogLevel(Level level)
- Overrides:
setLogLevelin classRemoteWebDriver
-
switchTo
public WebDriver.TargetLocator switchTo()
- Specified by:
switchToin interfaceWebDriver- Overrides:
switchToin classRemoteWebDriver
-
toString
public String toString()
- Overrides:
toStringin classRemoteWebDriver
-
findElementByClassName
public WebElement findElementByClassName(String using, String elementName)
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
public WebElement findElementByClassName(String using, String elementName, Float customAIThreshold)
-
findElementByClassName
public WebElement findElementByClassName(String using)
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.
-
findElementByClassName
public WebElement findElementByClassName(String using, Float customAIThreshold)
-
findElementsByClassName
public List<WebElement> findElementsByClassName(String using)
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
public WebElement findElementByCssSelector(String using, String elementName)
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
public WebElement findElementByCssSelector(String using, String elementName, Float customAIThreshold)
-
findElementByCssSelector
public WebElement findElementByCssSelector(String using)
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.
-
findElementByCssSelector
public WebElement findElementByCssSelector(String using, Float customAIThreshold)
-
findElementsByCssSelector
public List<WebElement> findElementsByCssSelector(String using)
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
public WebElement findElementById(String using, String elementName)
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
public WebElement findElementById(String using, String elementName, Float customAIThreshold)
-
findElementById
public WebElement findElementById(String using)
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.
-
findElementById
public WebElement findElementById(String using, Float customAIThreshold)
-
findElementsById
public List<WebElement> findElementsById(String using)
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
public WebElement findElementByLinkText(String using, String elementName)
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
public WebElement findElementByLinkText(String using, String elementName, Float customAIThreshold)
-
findElementByLinkText
public WebElement findElementByLinkText(String using)
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.
-
findElementByLinkText
public WebElement findElementByLinkText(String using, Float customAIThreshold)
-
findElementsByLinkText
public List<WebElement> findElementsByLinkText(String using)
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
public WebElement findElementByName(String using, String elementName)
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
public WebElement findElementByName(String using, String elementName, Float customAIThreshold)
-
findElementByName
public WebElement findElementByName(String using)
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.
-
findElementByName
public WebElement findElementByName(String using, Float customAIThreshold)
-
findElementsByName
public List<WebElement> findElementsByName(String using)
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
public WebElement findElementByPartialLinkText(String using, String elementName)
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
public WebElement findElementByPartialLinkText(String using, String elementName, Float customAIThreshold)
-
findElementByPartialLinkText
public WebElement findElementByPartialLinkText(String using, Float customAIThreshold)
-
findElementByPartialLinkText
public WebElement findElementByPartialLinkText(String using)
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
public List<WebElement> findElementsByPartialLinkText(String using)
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
public WebElement findElementByTagName(String using, String elementName)
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
public WebElement findElementByTagName(String using, String elementName, Float customAIThreshold)
-
findElementByTagName
public WebElement findElementByTagName(String using)
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.
-
findElementByTagName
public WebElement findElementByTagName(String using, Float customAIThreshold)
-
findElementsByTagName
public List<WebElement> findElementsByTagName(String using)
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
public WebElement findElementByXPath(String using, String elementName)
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
public WebElement findElementByXPath(String using, String elementName, Float customAiThreshold)
-
findElementByXPath
public WebElement findElementByXPath(String using)
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.
-
findElementByXPath
public WebElement findElementByXPath(String using, Float customAiThreshold)
-
findElementsByXPath
public List<WebElement> findElementsByXPath(String using)
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
public WebElement findByElementName(String elementName)
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
public WebElement findElementByElementName(String elementName, Float customAiThreshold)
Finds an element byelementName.- Parameters:
elementName- The label name of the element to be classified.- Returns:
- An element associated with
elementName. Throws NoSuchElementException otherwise.
-
findElementByElementName
public WebElement findElementByElementName(String elementName)
-
findByAI
public WebElement findByAI(String elementName)
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.
-
findByAI
public WebElement findByAI(String elementName, Float customAiThreshold)
-
scrollToElement
public void scrollToElement(WebElement element, Boolean scrollUp)
-
scrollPage
public void scrollPage(int amount)
-
close
public void close()
- Specified by:
closein interfaceWebDriver- Overrides:
closein classRemoteWebDriver
-
-