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>
  • With the given HTML the locator should work. May be it appears after some actions - so you may need to access it after those actions. – Dakshinamurthy Karra Oct 1 at 7:32
  • 2
    Add exception you received after running your code. – Bharat Mane Oct 1 at 7:38
  • Make sure your desired element is not located inside an IFRAME – Bill Hileman Oct 1 at 19:35

Sometimes the text() function not work, So try using ( . ) instead of text()

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

And In case there are multiple elements founded surround your xpath by index

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

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.