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
提交
取消
