首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Java中使用selenium在动态web表中使用文本来选择行?

如何在Java中使用selenium在动态web表中使用文本来选择行?
EN

Stack Overflow用户
提问于 2020-04-17 14:58:36
回答 1查看 197关注 0票数 0

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

代码语言:javascript
复制
<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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-18 23:14:56

试试这个:

代码语言:javascript
复制
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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61265744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档