19. isDisplayed vs isEnabled


isDisplayed vs isEnabled

isDisplayed

boolean isDisplayed()
Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute.

Returns:

Whether or not the element is displayed
Method used to verify presence of a web element within the webpage. The method is designed to result a Boolean value with each success and failure. 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.


isEnabled

boolean isEnabled()
Is the element currently enabled or not? This will generally return true for everything but disabled input elements.

Returns:

True if the element is enabled, false otherwise.
Method used to verify if the web element is enabled or disabled within the webpage. Like isDisplayed() method, it is designed to result a Boolean value with each success and failure. The method returns a “true” value if the specified web element is enabled on the web page and a “false” value if the web element is not enabled (state of being disabled) on the web page



After Executing code :




Sample Code:

package Others;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class isEnableDisable {
            public WebDriver driver;
            @Test
            public void testIsDiplayed_Enabled() throws Exception {
                        driver.get("http://www.plus2net.com/javascript_tutorial/listbox-disabled-demo.php");
                        //verify if drodpdown is displayed or not
                        //as it is returning True or False i will print the status
                        System.out.println("Dropdown is displayed : " +driver.findElement(By.name("Category")).isDisplayed());
                        //select radio button so Dropdown will be disabled
                        driver.findElement(By.xpath("//form[@id='f1']/input[2]")).click();
                        //Now dropdown is disable
                        //as it will return true or false i will print status
                        System.out.println("Dropdown is Enabled : " + driver.findElement(By.name("Category")).isEnabled());
                        //still the dropdown is displayed but it is in disabled status
                        System.out.println("Dropdown is displayed : " +driver.findElement(By.name("Category")).isDisplayed());
                       
                        Thread.sleep(3000);
            }

            @BeforeClass
            public void beforeClass() {
                        System.setProperty("webdriver.chrome.driver", "D:\\Softwares\\chromedriver_win32\\chromedriver.exe");   
                        driver = new ChromeDriver();
                        driver.manage().window().maximize();
                        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            }

            @AfterClass
            public void afterClass() throws Exception {
                        driver.quit();
            }

}

Output:

Dropdown is displayed : true
Dropdown is Enabled : false
Dropdown is displayed : true

1 comment:

  1. This is very informative blog and article thank you for sharing with us keep posting more information about salesforce trainingselenium training, selenium online training, selenium course,learn selenium course

    ReplyDelete