!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: Asserting webElement is not present  (Read 3562 times)

Danny Leblond

  • Web User
Asserting webElement is not present
« on: March 28, 2012, 03:30:02 PM »
Hey all,
 I have a test that deletes an element from my page (such as personal
 information) and thats working fine, but I'm having troubles deciding
 what I could assert to verify that the element is no longer available.
 If there any property to verify that an element exists or not?
 
What came to mind was something like: assertTrue(driver.findElement
 (By.name(theName)).isPresent());
 
Is this already available in some other form? Or is this bad practice?
 
Any information on asserting elements are no longer present would be
 useful.
 Thanks in advance,
 Danny

Simon Stewart

  • Web User
Re: Asserting webElement is not present
« Reply #1 on: March 28, 2012, 03:30:17 PM »
Hi,
 WebDriver throws a "NoSuchElementException" if an element is not
 present on a page. I tend to wrap this with a custom method:
 
public boolean isElementPresent(WebDriver driver, By locator) {
   try {
     driver.findElement(locator);
     return true;
   } catch (NoSuchElementException e) {
     return false;
   }
 

}
 

Which I then use in an "Assert.assertTrue" (or false)
 Regards,
 
Simon
 

- Show quoted text -

Danny Leblond

  • Web User
Re: Asserting webElement is not present
« Reply #2 on: March 28, 2012, 03:30:27 PM »
Thanks for the quick response, was thinking of doing this but wanted to confirm it wasn't already a feature!
 Danny
 

- Show quoted text -

Selenium Webdriver

Re: Asserting webElement is not present
« Reply #2 on: March 28, 2012, 03:30:27 PM »

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
1322 Views
Last post April 04, 2012, 04:24:59 PM
by Guilherme Garnier
1 Replies
950 Views
Last post April 09, 2012, 04:55:44 PM
by Guilherme Garnier
4 Replies
1389 Views
Last post April 12, 2012, 04:55:07 PM
by Luke Inman-Semerau
1 Replies
1213 Views
Last post April 19, 2012, 09:02:35 PM
by Selenium Webdriver Admin
1 Replies
570 Views
Last post May 03, 2012, 02:41:12 PM
by David
0 Replies
12 Views
Last post April 14, 2014, 11:46:03 AM
by LMJG
0 Replies
11 Views
Last post April 14, 2014, 08:03:36 PM
by SRiddick