如何找到在使用Selenium表中特定行? [英] How to find specific lines in a table using Selenium?

查看:520
本文介绍了如何找到在使用Selenium表中特定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个例子code:

Here is an example code:

<div id="productOrderContainer">
<table class="table gradient myPage">

所以这个表中productOrderContainer是有几列,并根据几件事情会有多行,所有有几个列。一个例子是:

So this table being in productOrderContainer has several columns and depending on several things will have several rows which all have several columns. An example is:

我想要做的是例如获得此表的第一行。 (行有编号的,如:&LT; TD ROWSPAN =1&GT; )在一个特定的这行跨度查找特定的值,然后再例如&LT; D​​IV&GT;

What I want to do is to for example get the first row of this table. ( rows have id's such as: <td rowspan="1"> ) And then again for example in this rowspan look for a specific value in a specific <div>

因此​​,在psudo- code什么,我想说的是:

So in psudo-code what I want to say is:

给我桌子上,让我第n行,让我的价值&LT; D​​IV ID ='东西'&GT;

Get me the table, get me the n'th row, get me the value in <div id='something'>

推荐答案

您可以尝试以下

int index = 0;
WebElement baseTable = driver.findElement(By.className("table gradient myPage"));
List<WebElement> tableRows = baseTable.findElements(By.tagName("tr"));
tableRows.get(index).getText();

您也可以遍历tablerows执行任何你想要的功能。

You can also iterate over tablerows to perform any function you want.

这篇关于如何找到在使用Selenium表中特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆