To check if Web Element is present
To verify if an element is present in the screen and based on the condition to proceed,
then we can check the size of element and if it is greater than zero then the element exists or else element does not exists
Ex:
Consider login screen where need to check if password field exists or not
let password is represented by id as pswrd
use the below command
List<WebElement> pwd = driver.findElements(By.id("pswrd"));
if(pwd.size()>0{
// password field exists;
}else{
// password field does not exists;
}
then we can check the size of element and if it is greater than zero then the element exists or else element does not exists
Ex:
Consider login screen where need to check if password field exists or not
let password is represented by id as pswrd
use the below command
List<WebElement>
if(pwd.size()>0{
// password field exists;
}else{
// password field does not exists;
}
Comments