Reputation: 67
There are 2 fields Address and Billing Address both fields throw suggestions.
my code is fine if I comment on the Address code the billing address code is working. If I comment on the billing address code the address code is working. but unable to run it when I comment out everything you know anything about this? The code is below.
//adding address and select from the suggestion bar here I'm selecting with ID
driver.findElement(By.id("entityAddress_0")).sendKeys("Khalifa city sector 13");
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS);
List <WebElement> suggestion = driver.findElements(By.className("pac-item")); //here I print all the value which are coming
//here I'm using for each loop and print the value so we can see all the value which appeared in suggestions
for (WebElement suggest : suggestion) {
if(suggest.getText().equalsIgnoreCase("Sector 13Khalifa City - Abu Dhabi - United Arab Emirates")) {
suggest.click();
break;
}
Thread.sleep(1000);
//now adding the billing address
driver.findElement(By.id("entityAddress_01")).sendKeys("Khalifa city sector 13");
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS);
List <WebElement> suggestions =driver.findElements(By.className("pac-item-query"));
for (WebElement suggests : suggestions) {
//System.out.println(suggests.getText());
if(suggests.getText().equalsIgnoreCase("Khalifa city"));
suggests.click();
}
}}}
Upvotes: 0
Views: 80
Reputation: 244
You've got a java error when you declare suggestions
twice.
You can't declare List <WebElement> suggestions = driver.findElement();
twice. You can do your first declaration but for your second one, the billing one, you need to remove List <WebElement>
and just do suggestions = driver.findElement(//your xpath)
for the second declaration
The two different suggestions
declarations should look exactly like this:
List <WebElement> suggestions = driver.findElements(By.className("pac-item"));
and
suggestions = driver.findElements(By.className("pac-item-query"))
Upvotes: 2