I have a dropdown which is disabled and I have to verify the same. How can I do it with an assert statement or any other method?
You can select the dropdown WebElement this way;
WebElement testDropDown = driver.findElement(By.id("testingDropdown")); Select dropdown = new Select(testDropDown);
But to check whether it is disabled, you can use isEnabled();
boolean isEnabledDropDown = driver.findElement(By.xpath("dropdown_xpath")).isEnabled();
Check the isEnabled() documentation
Therefore to assert that;
In case isEnabled is not working:
- Verify the DOM which may be having some attributes to represent it is disabled
- And then use element.getAttribute("attName");
If it doesn't work, you can go with the exception. Try to select a value as mentioned in the above code, surround it with try block and capture the result in your catch block.