Skip to content
Gleb Golovin edited this page Oct 10, 2016 · 4 revisions

Strategies

id

Use this when you know AutomationProperties.AutomationId attribute of an element.

driver.find_element_by_id('SearchBar')

name

Use this when you know Name attribute of an element.

driver.find_element_by_name('AddressLabel')

class name

Use this when you know ClassName attribute of an element.

driver.find_element_by_class_name('MySuperTextBox')

xpath

One of the main reasons for using XPath is when you don’t have a suitable id or name attribute for the element you wish to locate. For more examples, see locators values in feature-tests.

driver.find_elements_by_xpath("*[starts-with(@Name, 'Element_')]")

package testcases; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.By; import org.openqa.selenium.winium.DesktopOptions; import org.openqa.selenium.winium.WiniumDriver public class calculator {

public static void main(String[] args) throws MalformedURLException, InterruptedException {
    DesktopOptions option = new DesktopOptions();
    option.setApplicationPath("C:\\Windows\\System32\\calc.exe");
    WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999"), option);
    Thread.sleep(5);
    driver.findElement(By.name("Five")).click();
    driver.findElement(By.id("multiplyButton")).click();
    driver.findElement(By.name("Six")).click();
    driver.findElement(By.id("equalButton")).click();

} }

Clone this wiki locally