gpt4 book ai didi

java - Selenium 网络驱动程序: search an image from HTML table and perform some operation if that is found

转载 作者:太空宇宙 更新时间:2023-11-04 15:22:22 25 4
gpt4 key购买 nike

我正在使用 Selenium Webdriver、Java 和 TestNG。我正在尝试从 HTML 表中搜索图像,如果找到该图像,我需要单击其他按钮。例如:

  1. 有一个div,表头为
    名称地点事物警报
  2. 执行某些操作时,第四列中会显示一个警报图像。
  3. 所以我想搜索该警报图像,如果找到该警报图像,请单击“点击”按钮。

这是html代码

<th scope="col">
Detail
</th>

<th class="sortable" scope="col">

<a href="javascript:__doPostBack('reprot5','test$DateScored')">
Received
</a>

</th>

<th scope="col">

<th scope="col">
Alert
</th>

<th class="report6" scope="col">
Response
</th>

<th scope="col"/>

</tr>

</thead>

<tbody>

<tr class="reprot7">

<td>
test survey
</td>

<td>

<span>
Agent--Equiniti
</span>

</td>

<td>

<span>
28 November 2013 10:47:59
</span>

</td>

<td>

<span/>

</td>

<td>

<span>

<img class="justprintingImg" style="padding-left:10px;" src="../icon_alert.gif"/>

</span>

</td>

最佳答案

虽然没有经过测试,但我认为以下内容会给您带来同样的想法。

WebElement image = driver.findElement(By.xpath("//img[@src='../icon_alert.gif"));
if(image!=null){
//button click event
}

关于java - Selenium 网络驱动程序: search an image from HTML table and perform some operation if that is found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20284277/

25 4 0