Home > Blockchain >  Cannot locate option dropdown with value in selenium web driver
Cannot locate option dropdown with value in selenium web driver

Time:10-18

   wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOGON_selectedUser")));
   
   WebElement mySelectElement = driver.findElement(By.id("LOGON_selectedUser"));
   
   mySelectElement.click();
   
   
     Select dropdown= new Select(driver.findElement(By.id("LOGON_selectedUser")));
  
     dropdown.selectByVisibleText("HOTLINE-FAMILY SAFETY - Acting Supervisor");

Below is the error I'm getting:

Cannot locate option with text: HOTLINE-FAMILY SAFETY - Acting Supervisor I tried with by. value bit no luck. :(

However, I'm able to select the dropdown with statement mySelectElement.click(); but when I try to select the drop-down, I'm keep on getting cannot locate the element. Pls help.

Here is the DOM:

enter image description here

CodePudding user response:

The web page has been built using Angular. Please try to induce Explicit waits with Select class.

Select dropdown = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@name='selectedUser' and @id='LOGON_selectedUser' and @onchange]"))));
dropdown.selectByIndex(1);

or if that does not work, the below should work

((JavascriptExecutor) driver).executeScript("return document.getElementById('LOGON_selectedUser').selectedIndex = '"   index   "';)

where index is a variable, try to pass index number like 1,2,3 and so on...

  • Related