xpath, selenium, starts-with, contains, text

In xpath we can use functions, when we are familiar with the details of element.
The element details we can find in the inspector tools like firebug..etc

text()
starts-with()
contains()

======
1. suppose there is an element in the html like
     shopping
then in xpath
      driver.findElement(By.xpath("//span[text()='shopping']"));
       or
      driver.findElement(By.xpath("//span[starts-with(.,'shop')]"));
         here . refer to the text in the element

2. suppose there is an element in the html like
    
software testing help for sample

to recognize the above element, in xpath
       driver.findElement(By.xpath("//div[starts-with(@id,'testing')]"));
       OR
       driver.findElement(By.xpath("//div[contains(@id,'testing')]"));

3. for the same above example we can also use
       driver.findElement(By.xpath("//div[contains(@id,'testing') or contains(@name,'sample')]"));

Comments

Post a Comment