0
votes

HTML Section :

<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-focused" data-index="0" id="6609432f-2fd2-49c1-95df-6a330acecca0">admin</li>

Here the Xpath which I am trying :

 driver.findelement(by.xpath("//li[text()=//li[. = 'admin']"));

But getting exception :

invalid selector: Unable to locate an element with the xpath expression //li[text()=//li[. = 'admin'] because of the following error:

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//li[text()=//li[. = 'admin']' is not a valid XPath expression.

Exact look at UI and HTML code :

enter image description here

That field is auto complete.ID is changing dynamic of that element so I can not use id here to find element.

1

1 Answers

3
votes

Your XPath expression is not syntactically correct, there is an extra [, fix it:

//li[text()='admin']

Or, you may use . to refer to the text of the current node:

//li[. = 'admin']