Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Asserting Text In WebDriver

View previous topic View next topic Go down

Asserting Text In WebDriver

Post by Latha.p on Tue Feb 05, 2013 11:13 am

Hi,

How can we assertText, assertTextPresent, verifyText, verifyTextPresent in Webdriver.
Can any one please help me?

Latha.p
Active particpant
Active particpant

Posts : 11
Join date : 2013-01-06

Back to top Go down

Re: Asserting Text In WebDriver

Post by er.debu on Tue Feb 05, 2013 12:13 pm

Assert.assertequals(); you can use for matching text/numeric value,boolean value.

boolean bool=driver.findElement(By.xpath("xpath of the text")); it will return true or false.

String text=driver.fidnElement(By.xpath("xpath of the text")).getText();
this will return text of that xpath.Then u can compare with ur expected text by putting Assert.assertequals(text,"your expected text");

er.debu

Posts : 6
Join date : 2013-02-01
Age : 30
Location : Bangalore

Back to top Go down

Re: Asserting Text In WebDriver

Post by Latha.p on Tue Feb 05, 2013 2:06 pm

Thank u very much debu for ur reply.
Ya its worked.
But whats my prob is i tried on one website of asserting text. but i dont know where the mistake is iam getting error

following is the code.
import org.junit.Assert;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestAssertText {
public static void main(String[] args){
WebDriver d1=new FirefoxDriver();
d1.get("http://www.sriramatech.com/");
String text=d1.findElement(By.xpath(".header-headertitle")).getText();
Assert.assertEquals(text,"Welcome to ORKL SriRamaTech Enterprises!");
d1.close();
}
}

Please tell me where the mistake is and can u remodified that? Its very urgent for me

Latha.p
Active particpant
Active particpant

Posts : 11
Join date : 2013-01-06

Back to top Go down

Re: Asserting Text In WebDriver

Post by er.debu on Tue Feb 05, 2013 3:24 pm

hi latha,
Pls check below code.Hope it may work.


WebDriver d1=new FirefoxDriver();
driver.get("ur url");
Thread.sleep(5000);
String text=d1.findElement(By.xpath("//*[@id='header']/table/tbody/tr/td[2]/span[1]")).getText();
Assert.assertEquals(text,"Welcome to ORKL SriRamaTech Enterprises!");
d1.close();
}
}

er.debu

Posts : 6
Join date : 2013-02-01
Age : 30
Location : Bangalore

Back to top Go down

Re: Asserting Text In WebDriver

Post by Sponsored content Today at 8:52 am


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum