有两个字段地址和账单地址这两个字段都有建议
我的代码是好的,如果我评论地址代码的账单地址代码正在工作。如果我对帐单地址的地址代码是有效的。但是当我注释掉你所知道的关于这个的一切时,却无法运行它?代码如下:
//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();
}
}}}
你有java错误当你声明suggestions
两次。
不能声明两次List <WebElement> suggestions = driver.findElement();
。你可以做你的第一个声明要不是你的第二个,账单,你需要删除List <WebElement>
和suggestions = driver.findElement(//your xpath)
第二声明
两个不同的suggestions
声明应该完全像这样:
List <WebElement> suggestions = driver.findElements(By.className("pac-item"));
和
suggestions = driver.findElements(By.className("pac-item-query"))