Umamaheshwar Thota
Umamaheshwar Thota

Reputation: 521

In webdriver, how to verify dropdown field is displayed or not using Java

I need to verify whether the dropdown field is displayed in the screen or not using Java in webdriver. This dropdown field will display in this a screen after selecting the checkbox in another screen only.I have used the following code to verify the field is displayed or not but, it is not returning any value like true or false.

driver.findElements(By.name("ctl00$MasterPlaceHolder$DdlPwdExp"));
driver.findElements(By.name("ctl00$MasterPlaceHolder$DdlSessionExp"));
driver.findElements(By.name("ctl00$MasterPlaceHolder$DdlfailedLogin"));

Can any one help me on this. Help will be appreciated.

Upvotes: 0

Views: 2334

Answers (2)

Umamaheshwar Thota
Umamaheshwar Thota

Reputation: 521

First I have resolved my problem by using above answer from Khrol, and i have tried another method also, which resolved my problem completely.

int size = driver.findElements(By.name("ctl00$MasterPlaceHolder$DdlPwdExp")).size();
if (size > 0)
{
System.out.println("No. of Days for Password Expiration field: is displayed");
}
else
{
System.out.println("No. of Days for Password Expiration field: is not displayed");
}

Upvotes: 0

Igor Khrol
Igor Khrol

Reputation: 1788

Verifications should be done using xUnit-system and Asserts. E.g. JUnit or TestNG for Java. You can do the verification the following way with TestNG (for JUnit the order of arguments is slightly different):

Assert.assertEquals(driver.findElements(By.name("ctl00$MasterPlaceHolder$DdlPwdExp")).size(), 1, 
    "Password field wasn't found"); 
Assert.assertEquals(driver.findElements(By.name("ctl00$MasterPlaceHolder$DdlSessionExp")).size(), 1,
    "Some other field wasn't found"); 
Assert.assertEquals(driver.findElements(By.name("ctl00$MasterPlaceHolder$DdlfailedLogin")).size(), 1, 
    "Whatever field wasn't found"); 

Upvotes: 1

Related Questions