gpt4 book ai didi

java - 使用 Selenium 从 google 注册页面访问下拉列表

转载 作者:太空宇宙 更新时间:2023-11-04 11:50:47 26 4
gpt4 key购买 nike

我正在使用 selenium + firefox 浏览器访问以下链接

https://accounts.google.com/SignUp?service=mail&hl=en&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fpc%3Den-ha-apac-in-bk-refresh13&utm_campaign=en&utm_source=en-ha-apac-in-bk-refresh13&utm_medium=ha

driver.get(baseUrl); 其中 baseUrl 位于 url 上方。

我正在尝试选择英国。

driver.findElement(By.xpath("//div[@title='Location']")).sendKeys("United");

以上代码选择以 United 开头的第一个下拉值。

driver.findElement(By.xpath("//div[@title='Location']")).sendKeys("United Kingdom");

如果我使用上面的代码,即在之间插入空格,它不会按预期工作。

我如何选择英国。

谢谢

最佳答案

点击下拉菜单后直接点击它应该可以:

public void selectLocation(String CountryName) {
driver.findElement(By.xpath("//div[@title='Location']")).click();
driver.findElement(By.xpath("//div[@class='goog-menuitem-content' and text()='"+ CountryName + "']")).click();
System.out.println("点击选项 '"+ CountryName + "' 获取位置。");
}

关于java - 使用 Selenium 从 google 注册页面访问下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41860474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com