如何在 Selenium java 中选择 select

How to choose select in Selenium java

我有 wicket 应用程序,我想设置一个 select 值。问题是 chrome 驱动程序 returns 出现 RESPONSE FindElement ERROR

错误
no such element: Unable to locate element: {"method":"css selector","selector":"#id104"}
  (Session info: chrome=94.0.4606.81)

这是我的硒 java 代码:

System.setProperty("webdriver.chrome.driver", pathToDriver);
        System.setProperty("webdriver.chrome.logfile", "C:\app\chromedriver.log");

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setBinary("C:\app\GoogleChromePortable64\App\Chrome-bin\chrome.exe");
        WebDriver driver=new ChromeDriver(chromeOptions);

        driver.navigate().to(url);

        System.out.println(driver.getCurrentUrl());

        WebElement userTextField = driver.findElement(By.id("username"));
        userTextField.sendKeys(username);

        WebElement passwordTextField = driver.findElement(By.id("password"));
        passwordTextField.sendKeys(password);

        WebElement okButton =driver. findElement(By.id("OKButton"));
        okButton.click();

        WebElement crdbTab =driver. findElement(By.linkText("CRDB"));
        crdbTab.click();


        (new WebDriverWait(driver, 5)).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("iframe_app4"));

        WebElement uploadTab = driver.findElement(By.linkText("Upload"));
        uploadTab.click();

        System.out.println(driver.getCurrentUrl());
        WebElement fileUploadButton = driver.findElement(By.id("id5f"));
        fileUploadButton.sendKeys(filePath);

        driver.findElement(By.id("idb")).click();

        driver.findElement(By.className("main")).click();

        Select headerDataSelect = new Select(driver.findElement(By.id("id104")));
        headerDataSelect.selectByIndex(0);

代码失败于

Select headerDataSelect = new Select(driver.findElement(By.id("id104")));

有人可以就如何解决这个问题给出意见吗?

感谢帮助

尝试在那里添加一个等待,以便在访问元素之前加载元素。
而不是

Select headerDataSelect = new Select(driver.findElement(By.id("id110")));

尝试

wait = new WebDriverWait(driver, 30);
Select headerDataSelect = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id110"))));

还要确保 id 值 id110 是唯一的,而不是动态的。