Unable to locate Text element using XPath in Selenium



  • This is my HTML page and I have some problem with my automation code and it is not able to locate the element and this is the XPath I used:

    @FindBy(xpath="//div[contains(text(),'Done')]")
    

    HTML Code:

    <div class="col s4">
    
      <div data-radium="true">
    
        <div class="waves-effect waves-dark btn-large " data-radium="true" style="color: white; text-transform: capitalize; box-shadow: none; padding: 0px 2rem; border-radius: 5px; height: 50px; line-height: 50px; width: auto; cursor: pointer; background: rgb(0, 208, 156);">
    
          <div>I'm Done</div>
        </div>
      </div>
    </div>
    


  • Sometimes elements are not accessible directly. So, in test automation services we try including the parent div to locate that element. As per the given HTML, you can use below-mentioned locator that might help to resolve the issue.

    XPath: @FindBy(xpath="//div[@class='waves-effect waves-dark btn-large']//div[contains(text(),'Done')]")

    Further, please check whether the element is present inside an iFrame. If yes, please switch to the desired iframe first before using XPath

    If you still face any issue provide more HTML so that we can assist you with a better solution.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2