需要删除
硒网络驱动程序代码,我想这一个:
driver.findElement(By.xpath(".//a[contains(.,'terw')]")).findElement(By.xpath(".//img[@id='delete_fully_img'])")).click();
,但其没有工作,我的代码:
<table id="Table_1" class="dataTable" aria-describedby="Table_1_info" style="width: 100px;">
<thead>
<tr class="header" role="row">
<td class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 213px;">Point Name</td>
<td class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 149px;">Description</td>
<td class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 150px;">Date Added</td>
<td class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 46px;"/>
</tr>
</thead>
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr class="odd">
<td class=" ">
<a id="attachment_title_382" slider_number="0" onclick="AddPoints('edit', '382', '');" href="javascript:void(0);">terw</a>
</td>
<td class=" "/>
<td class=" ">02/21/2017</td>
<td class=" ">
<img id="delete_fully_img" onclick="deletePoint('', '382', '382', '0');" title="Delete Point" style="height:17px;width:17px;" src="http //close_icon.png"/>
</td>
</tr>
<tr class="even">
<td class=" ">
<a id="attachment_title_301" slider_number="0" onclick="AddPoints('edit', '301', '1');" href="javascript:void(0);">1</a>
</td>
<td class=" "/>
<td class=" ">02/15/2017</td>
<td class=" ">
<img id="delete_fully_img_1" onclick="deletePoint('', '301', '301', '0');" title="Delete Point" style="height:17px;width:17px;" src="http //close_icon.png"/"/>
</td>
</tr>
</tbody>
尝试以下任一代码。
说明:使用tr
标签的class属性,尽量使用text
方法首先要找到像02/21/2017
元素的文本。然后使用following
关键字继续使用img
标记。
driver.findElement(By.xpath("//tr[@class='odd']/td[contains(text(), '02/21/2017')]/..//following::img[@id='delete_fully_img']")).click();
OR
driver.findElement(By.xpath("//tr[@class='odd']/..//following::img[@id='delete_fully_img']")).click();
OR
driver.findElement(By.xpath("//img[@id='delete_fully_img']")).click();
OR
driver.findElement(By.xpath("//tr[@class='odd']//img[@id='delete_fully_img']")).click();
OR
driver.findElement(By.xpath("//tr[@class='odd']//child::img[@id='delete_fully_img']")).click();
感谢它的工作,在这个driver.findElement(By.xpath(“// tr [@ class ='odd']/td [contains(text() ,'02/21/2017')] /..// following :: img [@ id ='delete_fully_img']“))。click();有可能把名称而不是日期? – user3847594
不,你不能放置名称,因为你的'td'标签在这里只包含'date'。请参阅html'02/21/2017'如果问题已解决,请将此答案标记为已接受。 –
我已经创建了新的'xpath'。但它的理解更为复杂。试试这个xpath:''driver.findElement(By.xpath(“// tr [@ class ='odd']/td/a [contains(text(),'terw')] /..// following -sibling :: td [contains(text(),'02/21/2017')] /..// following-sibling :: td/img [@ id ='delete_fully_img']“))。click();' –
使用XPath: // tr [包含(@class,“even”)] // td/img [contains(@id,“delete_fully_img_1”)和包含(@title,“删除点”)] 希望它适合你。
试试这个如下: -
driver.findElement(By.xpath("//img[@id='delete_fully_img']"))
OR
driver.findElement(By.xpath("//tr[@class='odd']//img[@id='delete_fully_img']"))
OR
driver.findElement(By.xpath("//img[@id='delete_fully_img']/ancestor::tr[@class='odd']"))
你好@Paras,你的两个xpath都不行,因为你的目标是'a'标签。但在id属性包含''img'标签的'html'里面。 –
ohh我的坏..更新 – Paras
你最后的xpath在这里将不起作用,因为你的xpath会定位整行,所以在这里不是使用'ancestor'关键字来使用'child'关键字,所以它只会定位到特定的删除图标按钮。用'child'关键字查看我的最后一个答案。 –
问题不明确,请添加其他细节或删除的问题,如果它已经被问错。 – user3251882
错误?这是否真的发生?我只是想知道是否有人过来这个网站,并且“哎呀,我只是把这一切都错了。” – RSon1234
阅读文章。 http://stackoverflow.com/help/how-to-ask –