0

I have a dropdown and a button on a web page.please suggest how to verify if a WebElement(Button,Dropdown) is enabled Using TestNG framework?

one more thing when we work on TestNG we have to use assert in order to get the status of the test case. so if i want to know whether button is enabled.can i use assert here?

1

For Button

   elem = driver.find_element_by_id("myId")
if elem.is_enabled():
    elem.click()
else:
    pass # whatever logic to handle...

For DropDown

 Boolean dropdownPresent = driver.findElement("YOUR LOCATOR OF DROPDOWN").isDisplayed();

        if(dropdownPresent==true)
        {
            System.out.println("Dropdown is appearing");
        }
        else{
            System.out.println("Dropdown is not appearing");
        }

WebDriver has a W3C specification that details out the information about the different visibility preferences based out on the types of the web elements.

isDisplayed() is the method used to verify presence of a web element within the webpage. The method returns a “true” value if the specified web element is present on the web page and a “false” value if the web element is not present on the web page.

isDisplayed() is capable to check for the presence of all kinds of web elements available.

isEnabled() is the method used to verify if the web element is enabled or disabled within the webpage.

isEnabled() is primarily used with buttons.

isSelected() is the method used to verify if the web element is selected or not.

isSelected() method is pre-dominantly used with radio buttons, drop downs and checkboxes.

for more understanding check this link https://stackoverflow.com/questions/14156656/how-to-verify-element-present-or-visible-in-selenium-2-selenium-webdriver

Hope it helps Thanks

| improve this answer | |
  • @log_file: Thanks a lot. one more thing when we work on TestNG we have to use assert in order to get the status of the test case. so if i want to know whether button is enabled.can i use assert here? – iAutomate Aug 17 '16 at 3:03

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.