[英]xPath in Selenium - what am I doing wrong?
I have a page with the following snippet in the HTML: 我在HTML中有一个包含以下代码段的页面:
...
<tbody id="c_scopePane4_tbody">
<tr id="c_scopePane4_tr_header">
...
</tr>
</tbody>
...
Now I'm trying to specify the <tr>
tag with an XPath expression from within Selenium. 现在,我尝试使用Selenium中的XPath表达式指定
<tr>
标记。 Here's what I try: 这是我尝试的方法:
//tr[@id='c_scopePane4_tr_header']
This tells me 这告诉我
[error] locator not found: //tr[@id='c_scopePane4_tr_header'], error = Error:
Element //tr[@id='c_scopePane4_tr_header'] not found
But if I change the XPath expression to: 但是,如果我将XPath表达式更改为:
//*[@id='c_scopePane4_tr_header']
...then it works. ...然后工作。 What gives?
是什么赋予了?
It's working for me with the same snippet. 相同的代码段对我有用。 Perhaps there's something else in your HTML that's causing problems?
也许您的HTML中还有其他引起问题的内容? Do you have more than one
<tr>
(or any other element) with the same ID? 您是否有多个具有相同ID的
<tr>
(或任何其他元素)?
Because IDs are (meant to be) unique, you should be able to use your second XPath expression with confidence. 因为ID是(唯一的)唯一的,所以您应该能够放心地使用第二个XPath表达式。 Alternatively you can use the following, but be sure to precede your locator with
xpath=
so that Selenium knows the type of locator you are using: 另外,您可以使用以下命令,但请确保在定位器之前加上
xpath=
以便Selenium知道您正在使用的定位器类型:
xpath=id('c_scopePane4_tr_header')
Also, if you just want to select the <tr>
element then you can also use one of the following: 另外,如果只想选择
<tr>
元素,则还可以使用以下之一:
Alternate CSS Style locator: 备用CSS样式定位器:
css=tr#c_scopePane4_tr_header
or DOM Style: 或DOM样式:
dom=document.getElementById("c_scopePane4_tr_header")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.