Unable to select the data from dropdown using selenium webdriver 4.8.0

16 Views Asked by At

enter image description here

I couldn't select the value from the drop-down. Tried with the below mentioned

Inspect body/html body in attached image:

Tried with this

    Select selectBenefeciary = new Select(driver.findElement
            (By.xpath("//*[@id=\"beneficiary\"]")));
    selectBenefeciary.selectByVisibleText("FROBEL ACADEMY");

    Select selectBenefeciary = new Select(driver.findElement
            (By.xpath("//*[@id=\"beneficiary\"]")));
    selectBenefeciary.selectByIndex(1);
1

There are 1 best solutions below

1
Shawn On

There could be more than one reasons why selenium is not able to handle the dropdown. One of the reason could be that the script executes faster than the loading of the web page. Try using Selenium's Waits to effectively locate the element.

Try using Explicit Waits something like below:

Select selectBeneficiary = new Select(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.id("beneficiary"))));

Imports:

import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.By;