Selenium webinar
Locator etiquette
Login form filling
Move to a bigger framework
how to find elements on a page
Using Selenium with CBT's Cloudthey recommend using ID to find the element
Resilient: element_by_name
less good: find_element_by_css_selector
brittle: find_elements_by_xpath
very brittle: to find an element by text content, i.e.. 'sign up today'
data-
attribute selector, new in selenium. can work well alsoFirst test locally. It's quick, easy to learn.
Then it's easy with minimal changes run the tests on CBT's device cloud.
Add authentication, and capabilities and define browser parameters
Demo is in PythonHe adds a lot of sleeps to the driver so that he can see what's going on (
time.sleep(3)
in Python.creates a Chrome target with
driver = web drive.Chrome()
then uses driver
to talk to the browserThen adds a
try
and finally
. You need to make sure you start up and shut down your browser.
Responsive test
uses
driver.get("http://..")
to get a page.then
driver.set_window_size(...)
Responsive test plus look for items on the page
driver_find_element_by_css_selector("[data-name]")
and also does
driver.execute_script("...javascript...", e)
where e
is the found element you can for example scroll with
execute_script
there's also plural
driver.find_elements_by_css_selector
chains:
driver.find_element_by_name("username").send_keys("fff@dd.com")
and for the button:
driver.find_element_by_css_selctor("#button").click()
To continue
Then you need to check somehow that you successfully clicked on the element.
He uses wait until
webdriverwait(driver, 10),until(EC.presence_of_element_located(by.XPATH('path selector')))
to run on a cloud service
the code is on GitHub
My question:- best strategy to wait for elements/pages to load or appear (I'm using webdriverio)
- using screenshot compare (to further automate checking the results)
Visual Testing capabilities