2017-04-23 47 views
0

当使用硒读取下表时,我遇到困难。使用硒读取表格

HTML

定位器是如下

@FindBy(css = "table.table-bordered.table-striped") private WebElement storesTable;

List<WebElement> storeRows = storesTable.findElements(By.tagName("/tbody/tr"));

行的计数是0的运行代码时。任何帮助是极大的赞赏。

回答

1

这样做的原因是:你给无效TagName作为"/tbody/tr"再加上你需要如下改变你storesTable因为tr存在tbody下:

List<WebElement> storeRows = storesTable.findElements(By.tagName("tr")); 

@FindBy(css = "table.table-bordered.table-striped > tbody") 
private WebElement storesTable; 

,改变标记名后

+0

嗨@kushal,谢谢你的回复。这解决了我的问题 –

0

您正在提供xpath来代替tagName。

如果你想使用下面的标记名是声明

List<WebElement> storeRows = storesTable.findElements(By.tagName("tr")); 

否则,如果你想使用XPath下面是语句。

List<WebElement> storeRows = storesTable.findElements(By.xpath(".//tbody/tr")); 
+0

嗨Akarsh,谢谢你的回复。也会尝试你的解决方案 –