0

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>
4
  • 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. Oct 1, 2018 at 7:32
  • 2
    Add exception you received after running your code. Oct 1, 2018 at 7:38
  • 1
    Make sure your desired element is not located inside an IFRAME Oct 1, 2018 at 19:35
  • Voting to close unclear what you are asking. No response to what was your exception, did you look for an iFrame. May 2, 2019 at 8:32

2 Answers 2

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.

0

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]")

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