![](/img/trans.png)
[英]How to find attribute without value is present or not in HTML tag using Selenium?
[英]How to find the html tag using its attribute and its text both in selenium?
我有一个标签,假设
<td columnname="ID">DS199</td>.
现在,我必须基于属性columnname和标签文本都使用selenium找到该标签。 我使用的代码:
driver.findElement(By.xpath("//td[@columnname='ID' AND (text()='DS199')]"));
输出:
org.openqa.selenium.InvalidSelectorException:invalid selector: Unable to locate the element with the xpath expression //td[@columnname='ID' AND (text()='DS199')]
当要在代码上验证多个条件时,请让我知道获取webelement对象的正确方法。
尝试这个。 也许您的文本中有一些前导或尾随空格
"//td[@columnname='ID'][normalize-space(text())='DS199']"
它是and
,不是AND
:
//td[@columnname='ID' and (text()='DS199')]
另外,您可能需要测试td
的字符串值:
//td[@columnname='ID' and .='DS199']
如果您也想搭配,说
<td columnname="ID"><b>DS199</b></td>
或者,如果您想规范空白,则更加健壮,
//td[@columnname='ID' and normalize-space()='DS199']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.