[英]Not able to get element by Xpath in Selenium webdriver
HTML Section : HTML部分:
<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 : 这是我正在尝试的Xpath:
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[. 无效的选择器:无法使用xpath表达式// li [text()= // li [定位元素。 = 'admin'] because of the following error:
='admin'],因为出现以下错误:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//li[text()=//li[. 语法错误:无法在“文档”上执行“评估”:字符串'// li [text()= // li [。 = 'admin']' is not a valid XPath expression.
='admin']'不是有效的XPath表达式。
Exact look at UI and HTML code : 仔细查看UI和HTML代码:
That field is auto complete.ID is changing dynamic of that element so I can not use id here to find element. 该字段是自动完成的。ID正在更改该元素的动态,因此我无法在此处使用id来查找元素。
Your XPath expression is not syntactically correct, there is an extra [
, fix it: 您的XPath表达式在语法上不正确,还有一个额外的
[
,请修复:
//li[text()='admin']
Or, you may use .
或者,您可以使用
.
to refer to the text of the current node: 引用当前节点的文本:
//li[. = 'admin']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.