7

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?

Prasad
  • 472
  • 5
  • 15
BadHorsie
  • 14,135
  • 30
  • 117
  • 191

3 Answers3

10

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.

HKstrongside
  • 333
  • 1
  • 7
1

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");
}
Manigandan
  • 5,004
  • 1
  • 28
  • 47
  • `findElement` doesn't return null if the element is not found, but throws an `ElementNotFoundException`. See [the docs](http://www.seleniumhq.org/docs/03_webdriver.jsp#locating-ui-elements-webelements) – Matthijs Wessels Sep 19 '16 at 14:58
  • How can we configure that in Selenium IDE? – Philipp Sep 18 '20 at 12:51
0

Below might be useful for you.

Just pass your element to this method it will return true if that element is visible in dom otherwise it will return false.

isElementPresent(WebDriver driver,By by)  
 {  
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);  
    try  
    {  
       driver.findElement(by);  
       return true;  
    }  
    catch(Exception e)  
    {  
       return false;  
    }  
    finally  
    {  
       driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  
     }  
 } 

For more info see this blog post

Santoshsarma
  • 5,627
  • 1
  • 24
  • 39