Script Examples

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):
  # Example of locating elements using CSS selector and ID
  driver.navigate_to("https://appr.tc/")
  # Wait 10 seconds until "body" element is visible
  e(driver, "css", "body").wait_until_visible(seconds=10)
  # Find "join button" and click on it
  e(driver, "id", "join-button").click()

  # Wait for 10 seconds
  time.sleep(10)
def test(driver: TestUIDriver):
  # Example of locating elements using CSS selector
  driver.navigate_to("https://www.google.com")
  # Wait 10 seconds until "body" element is visible
  e(driver, "css", "body").wait_until_visible(seconds=10)
  # Find search bar element and type Loadero into it
  e(driver, "css", "input[type=text]").send_keys("Loadero")
  # Find search button and click it
  e(driver, "css", "input[value~='Google']").click()

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