本文介绍了选择xpath时Selenium WebDriver抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

driver.findElement(By.xpath("//input[@type="+"checkbox"+"]/following-sibling:://td[contains(text(),"+"template"+"]"))

我的HTML就是这样

<tr>
<td class="tablecontent">
<input type="checkbox" value="59781" name="templateIds">
</td>`enter code here`
<td class="tablecontent"> test11 </td>
</tr>

推荐答案

看起来像是把引号弄乱了.在XPath中使用单引号可以避免出现此类问题.

Looks like your messed up with quotes. Use single quotes in XPath to avoid issues like this.

// if template is the text within your XPath
driver.findElement(By.xpath("//input[@type='checkbox']/following-sibling:://td[contains(text(), 'template']"));

// if template is your variable, then it should be
driver.findElement(By.xpath("//input[@type='checkbox']/following-sibling:://td[contains(text(), " + template + "']"));

此外,请仔细阅读该错误,它会告诉您您已经需要足够的信息.如您所见,消息的选择器中没有引号.

Also, please read the error carefully, it tells enough information you need already. As you can see, there are no quotes in the selector in the message.

这篇关于选择xpath时Selenium WebDriver抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 22:43