- Latha.pActive particpant
- Posts : 11
Join date : 2013-01-06
Asserting Text In WebDriver
Tue Feb 05, 2013 11:13 am
Hi,
How can we assertText, assertTextPresent, verifyText, verifyTextPresent in Webdriver.
Can any one please help me?
How can we assertText, assertTextPresent, verifyText, verifyTextPresent in Webdriver.
Can any one please help me?
- er.debu
- Posts : 6
Join date : 2013-02-01
Age : 37
Location : Bangalore
Re: Asserting Text In WebDriver
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");
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");
- Latha.pActive particpant
- Posts : 11
Join date : 2013-01-06
Re: Asserting Text In WebDriver
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
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
- er.debu
- Posts : 6
Join date : 2013-02-01
Age : 37
Location : Bangalore
Re: Asserting Text In WebDriver
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();
}
}
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();
}
}
- webdriver + python, how to check for presence of text on page?
- Using Webdriver java :Obtaining an OTP(Ont time Password) PIn from an registered email ID and use the value in an text box field of my Webapp URL.
- How to verify the text on UI using Selenium webdriver using ruby
- How to verify particular TEXT color in web page using selenium webdriver?
- How to check the whether the text present in the page or under particular area or not in Webdriver
Permissions in this forum:
You cannot reply to topics in this forum
|
|