gpt4 book ai didi

java - 如何使用 Selenium 和 Java 从自动建议中选择一个选项?

转载 作者:行者123 更新时间:2023-12-02 02:15:12 28 4
gpt4 key购买 nike

我在自定义下拉列表中有这两个选项 - 英属印度领土印度。当我输入“印度”时使用selenium sendKeys,它无法在相应的国家/地区字段中输入印度,因为它无法区分下拉列表中的英国“印度领土”和“印度”值。

网站链接: https://www.westernunion.com/gb/en/send-money/app/register

WebElement country = driver.findElement(By.xpath("//input[@id=\"countryOfBirthField\"]"));

country.clear();
country.sendKeys(" india ");

最佳答案

英属印度领土印度这两个下拉选项中,在各自的国家/地区字段中选择印度,您可以使用以下解决方案:

  • 代码块:

    public class A_demo 
    {
    public static void main(String[] args) throws Exception
    {
    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    options.addArguments("disable-infobars");
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://www.westernunion.com/gb/en/send-money/app/register");
    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#countryOfBirthField")));
    element.sendKeys("india");
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//ul[@class='dropdown-menu ng-isolate-scope']//li/a[@title='India']/strong[text()='India']"))).click();
    }
    }
  • 浏览器快照:

countryOfBirthIndia

关于java - 如何使用 Selenium 和 Java 从自动建议中选择一个选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57308447/

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