Script Examples
Locating elements
By using CSS selector
element = e(driver, "css", ".some-class")
By using xPath
element = e(driver, "xpath", "//some-element")
By using ID
element = e(driver, "id", "some-id")
By using class name
element = e(driver, "className", "some-class")
By using name
element = e(driver, "name", "some-name")
def test(driver: TestUIDriver):
def move_to_element(element):
# Moves element in view
# param: element: TestUIElement
element.get_element().location_once_scrolled_into_view
page_title = "The GitHub Shop | Home"
driver.navigate_to("https://thegithubshop.com")
# Verify page title
if driver.get_driver().title != page_title:
driver.set_error("page title does not match expected")
driver.raise_errors()
# Take screenshot of shop page
driver.save_screenshot("website_shop.png")
# Move to track order button
move_to_element(e(driver, "css", "[title='Track my order']"))
# Navigate to track my order page
e(
driver, "css", "[title='Track my order']"
).wait_until_visible().click()
# Take screenshot of login page
driver.save_screenshot("login_page.png")
def test(driver: TestUIDriver):
# Example of locating elements using CSS selector
driver.navigate_to("https://www.bing.com")
# Wait 10 seconds until page is visible and take a screenshot
e(driver, "css", ".dimmer").wait_until_visible(seconds=10)
driver.save_screenshot("website_bing.png")
# Find search bar element and type "QA Processes" into it
e(driver, "css", "[type=search]").send_keys("QA Processes")
# Find search button and click it
e(driver, "css", "#search_icon").wait_until_visible(seconds=10).click()
# Wait 10 seconds until search results are visible and take a screenshot
e(driver, "css", "[aria-label='Search Results']").wait_until_visible(seconds=10)
driver.save_screenshot("search_results.png")
Using Py-TestUI Element Assertion methods
element.
(.no())
.is_visible()
.is_visible_in(seconds)
.visible_for(seconds)
.wait_until_visible(seconds, log)
.wait_until_attribute(attr, text, seconds)
.wait_until_contains_attribute(attr, text, seconds)
.wait_until_contains_sensitive_attribute(attr, text, seconds, log)
You can find detailed descriptions and more examples in Py-TestUI wiki