Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium IDE - How to check that an element is (CSS) visible?

Example 1: Checking that a Twitter Bootstrap modal has opened.

The modal already exists on the page but is hidden with CSS until the modal is opened. So how do I verify that the modal actually opened?

Example 2: Checking that a user error message div was displayed.

The error message div always exists but is hidden with CSS until it is needed. How do I verify that the message is visible?

like image 803
BadHorsie Avatar asked Feb 07 '13 12:02

BadHorsie


2 Answers

You could try using the verifyVisible command. This looks at the css to see if visibility or display is set. It will return true if either of these are visible or returns false otherwise. You will need to pass in a locator. Use the element of the modal that is being controlled by the css.

like image 197
HKstrongside Avatar answered Sep 22 '22 11:09

HKstrongside


Answer 1:

You can check the modal status by checking the Presence or Visibility of a Web Element in the modal.

Answer 2:

You can check the Visibility parameter of the error message.

To check Element Present:

if(driver.findElements(By.xpath("value")).size() != 0){
System.out.println("Element is Present");
}else{
System.out.println("Element is Absent");
}

Or

if(driver.findElement(By.xpath("value"))!= null){
 System.out.println("Element is Present");
}else{
System.out.println("Element is Absent");
}

To check Visible:

if( driver.findElement(By.cssSelector("a > font")).isDisplayed()){
System.out.println("Element is Visible");
}else{
System.out.println("Element is InVisible");
}
like image 27
Manigandan Avatar answered Sep 22 '22 11:09

Manigandan