gpt4 book ai didi

java - 如何使用Java中的selenium在动态Web表中使用文本选择行?

转载 作者:行者123 更新时间:2023-12-01 17:22:36 25 4
gpt4 key购买 nike

在我的应用程序中,我的项目列表在表格中动态增长。我需要使用项目名称选择一个项目。选择按钮位于第二列,项目名称位于第三列。如何使用项目名称打开项目?

<table class="ui celled definition sortable striped compact table" xpath="1">
<thead class="full-width">
<tr>
<th colspan="9">
<div role="combobox" aria-expanded="false" class="ui search selection dropdown per-page">
<input aria-autocomplete="list" autocomplete="off" class="search" tabindex="0" type="text" value=""/>
</div>
<a href="/project-setup">
<button class="ui orange big circular icon right floated button">
<i aria-hidden="true" class="plus icon"/>
</button>
</a>
</th>
</tr>
<tr>
<th class="select-delete-check-box">
<div class="ui fitted checkbox">
<input class="hidden" id="selectAll" readonly="" tabindex="0" type="checkbox" value=""/>
<label for="selectAll"/>
</div>
</th>
<th> Open </th>
<th>ID</th>
<th>Owner</th>
<th>Members</th>
<th>Created At</th>
<th>Last Updated</th>
</tr>
</thead>
<tbody>
<tr>
<td class="select-delete-check-box">
<div class="ui fitted checkbox">
<input class="hidden" id="5e992e2b14d2d67c91eb51c9" readonly="" tabindex="0" type="checkbox" value=""/>
<label for="5e992e2b14d2d67c91eb51c9"/>
</div>
</td>
<td class="collapsing">
<a href="/project-setup?id=5e992e2b14d2d67c91eb51c9">
<button class="ui green big circular icon right floated button">
<i aria-hidden="true" class="pencil icon"/>
</button>
</a>
</td>
<td>
<div class="step">
<div class="content">
<div class="title" style="font-size: 1.2em; font-weight: bold;">A</div>
<div class="description">
<span>
<i aria-hidden="true" class="blue globe icon"/>3,4</span>
<br>
<span>
<i aria-hidden="true" class="red map marker alternate icon"/> Poland</span>
</div>
</div>
</div>
</td>
<td>abc@abc.com</td>
<td/>
<td>17/04/2010, 09:48:51</td>
<td>17/04/2010, 09:48:51</td>
</tr>
<tr>
<td class="select-delete-check-box">
<div class="ui fitted checkbox">
<input class="hidden" id="5e97f0a0adba5850643c7202" readonly="" tabindex="0" type="checkbox" value=""/>
<label for="5e97f0a0adba5850643c7202"/>
</div>
</td>
<td class="collapsing">
<a href="/project-setup?id=52">
<button class="ui green big circular icon right floated button">
<i aria-hidden="true" class="pencil icon"/>
</button>
</a>
</td>
<td>
<div class="step">
<div class="content">
<div class="title" style="font-size: 1.2em; font-weight: bold;">B</div>
<div class="description">
<span>
<i aria-hidden="true" class="blue globe icon"/> 1,2</span>
<br>
<span>
<i aria-hidden="true" class="red map marker alternate icon"/> Tamil Nadu, India</span>
</div>
</div>
</div>
</td>
<td>abc@abc.com</td>
<td/>
<td>16/04/2010, 11:14:00</td>
<td>16/04/2010, 17:08:01</td>
</tr>
</tbody>
</table>

最佳答案

试试这个:

WebElement table=driver.findElement(By.tagName("tbody"));
table.findElement(By.xpath("//div[@class='title' and contains(text(),'A')]/ancestor::td[1]/parent::tr/td[2]/a/button")).click();

关于java - 如何使用Java中的selenium在动态Web表中使用文本选择行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61265744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com