Home > Enterprise >  How to choose select in Selenium java
How to choose select in Selenium java

Time:02-26

I have wicket aplication, and I want to set one select value. Problem is that chrome driver returns error with RESPONSE FindElement ERROR

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

enter image description here

Here is my selenium java code:

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);

Code fails on

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

Can someone give a point on how to solve this issue?

Thanks for help

CodePudding user response:

Try adding a wait there to make elements loaded before accessing them.
Instead of

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

Try

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

Also make sure the id value id110 is unique and not dynamic here.

  • Related