Wednesday, 15 July 2015

Selenium and XPath

.//div[a[i[@class='fa fa-info-circle']]]//following-sibling::div[2]

To navigate to path, use: /.. or parent_tag name[and child xpath] 
eg:

1.       .//div[a[i[@class='fa fa-info-circle']]]                parent_tag[]: takes to parent element

2.        //[@class='fa fa-info-circle']/../..                      /..               : takes to parent element.


Consider below is the html source code:
div
      a
         i class="fa fa-info-circle"



----------------------
Contains text using xpath:           $x("//p[@class='help-block']/a[contains(text(),'here')]")
OR
for exact text matching using xpath: $x("//p[@class='help-block']/a[text()='here']")

3. Any tag having specific attribute:

      driver.findElement(By.xpath(".//*[@id='account']/a")).click();
 

No comments:

Post a Comment