SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Dec 2001
    Location
    Baton Rouge, LA, USA
    Posts
    407
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Assert Text is not on page

    In selenium 2 i am trying to assert that there is no text on the page using webDriver and i can not figure out how to do it this is what i want to do just need the correct syntax.

    VerifyFalse(selenium.isTextPresent ("id=idError")); the text is Please enter a valid ID
    Robby
    Geaux LSU

  2. #2
    SQA Knight
    Join Date
    May 2006
    Location
    Playa Del Rey, California, United States
    Posts
    2,592
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0
    In Webdriver, don't use any of the "selenium" stuff outside of the webdriver package. That's just there for people who are using webdriver backed seleniumRC for people who are in the process of porting a lot of selenium scripts to Webdriver over from RC.

    In webdriver, you'll do the following:

    assertFalse( driver.findElementBy(By.tag("body")).text().indexO f("idError") > 0 );

    So what this statement does, is the following...
    1. driver.findElementBy(By.tag("body")) - gets the refrence to the body tag, which is basically the content of the entire page.
    2. '.text()' will return you a string with the text content of the web welement.
    3. '.indexOf('search string')' will return you a position index of that string. If the position is positive, that means that string exists, if it returns negative, that means the string was not found.
    4. assertFalse tells your unittest framework a test should fail if the condition is not met. In thise case, we want the position ID to be negative because the text should not be found.
    David Lai
    SDET / Consultant
    LinkedIn profile

  3. #3
    Member
    Join Date
    Dec 2001
    Location
    Baton Rouge, LA, USA
    Posts
    407
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    assertFalse does not exist

    when i put assertFalse in it does not rec that it is a method.

    i am including
    org.openqa.selenium.*


    Quote Originally Posted by dlai View Post
    In Webdriver, don't use any of the "selenium" stuff outside of the webdriver package. That's just there for people who are using webdriver backed seleniumRC for people who are in the process of porting a lot of selenium scripts to Webdriver over from RC.

    In webdriver, you'll do the following:

    assertFalse( driver.findElementBy(By.tag("body")).text().indexO f("idError") > 0 );

    So what this statement does, is the following...
    1. driver.findElementBy(By.tag("body")) - gets the refrence to the body tag, which is basically the content of the entire page.
    2. '.text()' will return you a string with the text content of the web welement.
    3. '.indexOf('search string')' will return you a position index of that string. If the position is positive, that means that string exists, if it returns negative, that means the string was not found.
    4. assertFalse tells your unittest framework a test should fail if the condition is not met. In thise case, we want the position ID to be negative because the text should not be found.
    Robby
    Geaux LSU

  4. #4
    SQA Knight
    Join Date
    May 2006
    Location
    Playa Del Rey, California, United States
    Posts
    2,592
    Post Thanks / Like
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0
    You need to do a static import of whatever unit testing or testing framework you're using. For example, a JUnit test will look like this,

    Code:
    import static junit.framework.Assert.*;
    
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    
    public class TestClass {
    
    	@Test
    	public void test() throws Exception{
    		WebDriver driver = new FirefoxDriver();
    		driver.get("http://www.google.com");
    		WebElement body = driver.findElement(By.tagName("body"));
    		
    		assertTrue(body.getText().indexOf("YouTube") >= 0);
    	}
    
    }
    David Lai
    SDET / Consultant
    LinkedIn profile

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 05:39 AM.

Copyright BetaSoft Inc.