这是我的代码,但它没有选择值
WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F<mpl=default");
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[@class='goog-inline-block goog-flat-menu-button jfk-select']")).click();
Thread.sleep(3000);
List<WebElement>menu=driver.findElements(By.xpath(".//*[@class='goog-menuitem-content']"));
Thread.sleep(3000);
for(int i=0;i<menu.size();i++){
WebElement element=menu.get(i);
String innerhtml=element.getAttribute("innerHTML");
if(innerhtml.contentEquals("April"))
{
element.click();
break;
}
System.out.println("value of dropdown "+innerhtml);
}
driver.quit();
最佳答案
尝试以下代码:
driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F<mpl=default");
Thread.sleep(3000);
driver.findElement(By.xpath("//span[@id='BirthMonth']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//div[@class='goog-menuitem-content' and text()='April']")).click();
Thread.sleep(3000);
关于selenium - 如何通过Selenium Webdriver在gmail注册页面中选择生日(月份)下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40676651/