需要selenium web驱动程序代码进行删除

时间:2017-02-21 08:05:22

标签: java selenium-webdriver

table image

我试过这个:

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>

3 个答案:

答案 0 :(得分:0)

使用xpath: // tr [contains(@class,&#34; even&#34;)] // td / img [contains(@ id,&#34; delete_fully_img_1&#34;)并包含(@title,&#34;删除点&#34)] 希望它适合你。

答案 1 :(得分:0)

请尝试以下任何代码。

说明:使用tr标记的class属性,尝试使用02/21/2017方法首先找到text之类的元素文本。然后使用img关键字继续following代码。

 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();

答案 2 :(得分:0)

请尝试以下方法: -

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']"))