while (i < 165) { i = i + 1; ArrayList url[]; url.add(driver.findElement(String.valueOf(By.xpath("//*[@id=\"villages\"]/tbody/tr[" + i + "]/td[3]/a")).getAttribute("href")));}我收到以下錯誤。The method getAttribute(String) is undefined for the type String.我真的不確定發生了什么。數組列表應該像一個字符串數組?和得到屬性(字符串)是一個字符串...所以我不知道為什么這是不兼容的。有什么想法嗎?如果我嘗試在將其添加到數組列表之前創建一個變量來攜帶該值,我會收到此錯誤。無法在數組類型數組列表 [] 上調用添加(字符串)
2 回答

慕容森
TA貢獻1853條經驗 獲得超18個贊
您的代碼應該像這樣將所有URL添加到列表中:
while (i < 165) {
i = i + 1;
ArrayList<String> url = new ArrayList<String>();
url.add(driver.findElement(By.xpath("//*[@id='villages']/tbody/tr[" + i + "]/td[3]/a")).getAttribute("href"));
}
添加回答
舉報
0/150
提交
取消