!!

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: Verify that text is present on page  (Read 3392 times)

gdtyra

  • Web User
Verify that text is present on page
« on: March 28, 2012, 04:12:05 PM »
Selenium has the 'isTextPresent' method which just verifies that the
 given text exists somewhere on the page. I'm wondering if WebDriver
 has this capability built in as well. I've been making do with
 searching for various elements and looking in the database, however
 there are times when I think it would be useful to just make sure some
 text is on the page.
 For example, I am increasing the quantity of an item and looking in
 the database to verify that it has been updated, however it would be a
 lot easier to simply verify that "Quantity: 2" or whatever exists on
 the page.
 
Can WebDriver do this easily, or is there a work around you would
 recommend?
 
Thanks!

Steve CCRP

  • Web User
Re: Verify that text is present on page
« Reply #1 on: March 28, 2012, 04:12:21 PM »
WebDriver can do this.  The getText method will return all visible
 text from an element.  So if you do a getText on the body tag, you can
 get all the text and see if it contains the text you are looking for.
 For example:
 
WebDriver driver = new FirefoxDriver();
 driver.get("http://www.google.com");
 WebElement bodyTag = driver.findElement(By.tagName("body"));
 
if (bodyTag.getText().contains("Text I am looking for") {
   // do something
 

}
 

I imagine it's pretty slow though....
 On Jul 17, 4:31 pm, gdtyra <grantt...@gmail.com> wrote:
 

- Show quoted text -

Grant Tyra

  • Web User
Re: Verify that text is present on page
« Reply #2 on: March 28, 2012, 04:12:31 PM »
Ah, thanks! I suppose I could speed it up by just looking at a
 specific div or something too.
 
- Show quoted text -

Selenium Webdriver

Re: Verify that text is present on page
« Reply #2 on: March 28, 2012, 04:12:31 PM »

 

Related Topics

  Subject / Started by Replies Last post
18 Replies
4610 Views
Last post February 21, 2012, 02:15:25 PM
by Ana Stavreva
2 Replies
3733 Views
Last post February 22, 2012, 06:47:54 PM
by LizLeong
1 Replies
1295 Views
Last post April 19, 2012, 09:02:35 PM
by Selenium Webdriver Admin
6 Replies
1179 Views
Last post July 04, 2012, 04:22:37 PM
by Rovin
3 Replies
1503 Views
Last post July 25, 2012, 03:34:01 PM
by dlai
4 Replies
1564 Views
Last post July 26, 2012, 03:10:24 PM
by Carrying_Smiles
0 Replies
325 Views
Last post October 07, 2013, 06:48:14 AM
by abhi