0

I am unable to select an option from the drop-down menu. The right-click functionality is disabled on the drop-down, and whenever any button is clicked, the drop-down closes. To work around this, I manually selected the option and extracted the XPath using SelectorHub. However, I am encountering the following error:

Exception in thread 'main' org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been 'select' but was 'div'"

Here is my code:

WebElement dropdownElement = driver.findElement(By.cssSelector(".selct-control.css-b62m3t-ontainer"));
dropdownElement.c`your text`lick();
Thread.sleep(3000);
WebElement objSelect = (WebElement) new Select(dropdownElement);
objSelect = driver.findElement(By.xpath("//div[contains(text(),'Final Returned (2)')"));
objSelect.click();
Thread.sleep(3000);

2 Answers 2

1

The exception should be caused by

WebElement objSelect = (WebElement) new Select(dropdownElement); 

It is a div element, but not select element.

Can you try to update your "objSelect" to:

WebElement objSelect = driver.findElement(By.xpath("//div[contains(text(),'Final Returned (2)')"));  
Sign up to request clarification or add additional context in comments.

Comments

0

Why are you casting a Select object to a WebElement? You can simply use the Select object to select the options, assuming that your element is a 'select' tag. Try this:

Select objSelect = new Select(dropdownElement);
objSelect.selectByVisibleText("Final Returned (2)");

This way you don't have to call any click methods. Note that there are other methods available on the Select class that might work better for you, instead of the selectByVisibleText

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.