0

I am trying to the following element:

<span data-dojo-attach-point="lN" role="btn" aria-selected="false" class="xTreeNLbl">Find</span>

The following is the Java code:

private WebElement search_btn = driver.findElement(By.xpath("//div[@data-dojo-attach-point='lN' and contains(text(),'Find')"));
search_btn.click();

It's unable to find the element. Please help. Thanks.

Adrija
  • 99
  • 2
  • 11

4 Answers4

3

you are wrong at the xpath //div
as this is <span> tag not <div> tag you should write like this,

driver.findElement(By.xpath("*//span[text()='Find']")).click();
Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29
3

Your xpath is almost correct, you just need to correct tag name with Span

driver.findElement(By.xpath("//span[@data-dojo-attach-point='lN' and contains(text(),'Find')"));
Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
0

One option may be to try and find the element using one of it's attribute, like its class if it's unique. Taken from this previous question (Find element by attribute), the formula is:

element[attribute='attribute-value']

So if you have,

<a href="mysite.com"></a>

You can find it using:

By.cssSelector("a[href='mysite.com']");

AbsoluteSpace
  • 710
  • 2
  • 11
  • 21
0

Please try with the follow code:
//span[@role='btn' and @class='xTreeNLbl']

If this code does not solve your error, pass me the html dom code of the page and I will help.