Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
Latha.p
Active particpant
Active particpant
Posts : 11
Join date : 2013-01-06

Asserting Text In WebDriver Empty 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?
avatar
er.debu
Posts : 6
Join date : 2013-02-01
Age : 37
Location : Bangalore

Asserting Text In WebDriver Empty 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");
avatar
Latha.p
Active particpant
Active particpant
Posts : 11
Join date : 2013-01-06

Asserting Text In WebDriver Empty 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
avatar
er.debu
Posts : 6
Join date : 2013-02-01
Age : 37
Location : Bangalore

Asserting Text In WebDriver Empty 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();
}
}
Sponsored content

Asserting Text In WebDriver Empty Re: Asserting Text In WebDriver

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