Reputation: 161
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")));
}
I get the following error.
The method getAttribute(String) is undefined for the type String.
I'm not really sure what's going on. Arraylist should be like a array of strings? and getAttribute(String) is a string... So I have no idea why this is not compatible. Any ideas?
if I try making a variable to carry the value before I add it to the arraylist, i get this error. Cannot invoke add(String) on the array type ArrayList[]
Upvotes: 0
Views: 577
Reputation: 7708
Your code should be like this to add all URL's in a list :
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"));
}
Upvotes: 2
Reputation: 469
static String valueOf(arg)
Returns the string representation of the given argument.
and String class API dont have method getAttribute as such
Upvotes: 0