-1

I am trying an automation script with amazon and trying to select the category drop-down on the home page of amazon, but unable to do.

I am providing the code below.

WebElement Catagory = driver.findElement(By.id("searchDropdownBox"));
Select DropDown = new Select(Catagory);
DropDown.selectByVisibleText("Electronics");
0
1

The problem most probably is because no option text is visible by default.

enter image description here

You can either click on the dropdown (plus waiting for the bar appearance of course) or select by value:

DropDown.selectByValue("search-alias=electronics-intl-ship");

enter image description here

3
  • Hey Thanks for the help. As suggested i have made changed in my code and now getting this error "ElementNotInteractableException" .providing the piece of modiefied code WebElement Catagory = driver.findElement(By.id("searchDropdownBox")); Select DropDown =new Select(Catagory); DropDown.selectByValue("search-alias=electronics"); driver.quit(); It woukld be great if you can help me with this. I am new to selenium Dec 1 '20 at 12:54
  • Try clicking in the select before creating the DropDown object, obviously waiting for its opening after clicking. Dec 1 '20 at 13:45
  • Helloi have tried that also but nothing happenedWebElement Catagory = driver.findElement(By.id("searchDropdownBox")); Catagory.click(); Select DropDown =new Select(Catagory); DropDown.selectByValue("search-alias=electronics"); Dec 1 '20 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.