Skip to main content

Find By AI Method

SmartDriver adds additional methods to allow you to only use element names to find elements. This will return the Selenium Element that best matches the visual one.

Below is the same test case as the basic example where we will search for hello world on Google.com.

tip

You can write your entire test, and then execute it with interactive mode to quickly write larger tests.

from time import sleep

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

from devtools_ai.selenium import SmartDriver

def _main() -> None:
"""Main driver"""
chrome_driver = Chrome(service=Service(ChromeDriverManager().install()))

# Convert chrome_driver to smartDriver
driver = SmartDriver(chrome_driver, "??API_KEY??")

# Navigate to Google.com
driver.get("https://google.com")
sleep(1)

# Find the searchbox and send "hello world"
searchbox_element = driver.find_by_ai("searchbox")
searchbox_element.send_keys("hello world\n")

sleep(2)

driver.quit()


if __name__ == "__main__":
_main()