2017-04-23 51 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,謝謝你的回覆。也會嘗試你的解決方案 –