Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用xpath查找名称中带有下划线的元素_Xpath_Selenium Webdriver_Unique - Fatal编程技术网

使用xpath查找名称中带有下划线的元素

使用xpath查找名称中带有下划线的元素,xpath,selenium-webdriver,unique,Xpath,Selenium Webdriver,Unique,我试图单击一个动态更改ID和xpath的webelement。我看不到任何其他信息可以直接用于在每次加载页面时唯一地标识元素 以下是元素的Xpath: .//*[@id='isc_SB']/table/tbody/tr/td <table width="74px" height="30px" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="OBToolbarTextButtonFocus

我试图单击一个动态更改ID和xpath的webelement。我看不到任何其他信息可以直接用于在每次加载页面时唯一地标识元素

以下是元素的Xpath:

.//*[@id='isc_SB']/table/tbody/tr/td
<table width="74px" height="30px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="OBToolbarTextButtonFocusedOver" valign="center" nowrap="true" align="center" onfocus="isc_OBToolbarActionButton_3.$47()" tabindex="-1">
Pu
<u>b</u>
lish
</td>
</tr>
</tbody>
</table>
这将在每次页面加载时随ID一起更新

以下是同一元素的HTML代码:

.//*[@id='isc_SB']/table/tbody/tr/td
<table width="74px" height="30px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="OBToolbarTextButtonFocusedOver" valign="center" nowrap="true" align="center" onfocus="isc_OBToolbarActionButton_3.$47()" tabindex="-1">
Pu
<u>b</u>
lish
</td>
</tr>
</tbody>
</table>
尝试3:

publish = .//*[@id='isc_S7']/table/tbody/tr/td # this is just an example to show id, xpath and everything is dynamic.

请帮忙。谢谢。

不确定是否可以仅使用
xpath
来完成此任务。作为解决办法,这可能会有所帮助

//td[contains(text(),'Pu')]/u[text()='b']

在XPath中,元素节点的字符串值定义为其所有子代文本节点的串联,因此如果有

<td>Pu<u>b</u>lish</td>
如果像你的问题一样,
u
元素的两边都有新行,那么你需要更具创造性,例如

//td[normalize-space() = 'Pu b lish']
如果你想涵盖这两种情况,那么

//td[translate(normalize-space(), ' ', '') = 'Publish']

另一方面,尝试2不起作用的原因是
contains
希望它的两个参数都是字符串,但在您的示例中
text()
提供了一组两个文本节点(“Pu”和“lish”),将一个节点集转换为字符串意味着按照文档顺序只取集合中第一个节点的值,而忽略其他节点的值。

谢谢@ian roberts,对于精彩的解释和回答,它起到了作用。
//td[translate(normalize-space(), ' ', '') = 'Publish']