Nick Kahn
Nick Kahn

Reputation: 20078

How to verify text using Selenium Webdriver,

UPDATE 2:

something is very strange happening here...

as compare to my previous code, i wanted to know what exactly its getting the .Text and I found something weird the first line of code returns me A11 and not sure where does it coming from

string _name = driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_EditControl1_gv']/tbody/tr[11]/td[3]")).Text;

//its failing no wonder...

Assert.IsTrue(_name.Equals("Selenium"));

but how come its working with firefox?

UPDATE:

using C#

here is the code i am using and its working fine with Firefox but not with IE8

Assert.IsTrue(driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_EditControl1_gv']/tbody/tr[11]/td[3]")).Text.Equals("Selenium"));

get this error:

 failed: Assert.IsTrue failed. 

Upvotes: 1

Views: 39111

Answers (3)

squeemish
squeemish

Reputation: 147

Internet Explorer has a different reading of XPaths than almost all of the other browsers. IE5 and later has implemented that [0] should be the first node, but while most of the other browsers have the first node as [1].

You will need to rewrite your XPath expression by decreasing the node by one.

Upvotes: 0

Prashant Shukla
Prashant Shukla

Reputation: 1389

The way xpath is rendered in IE is different from the way it is in Firefox. So its real possible that your xpath is capturing totally different text in IE. try getting output(Console.WriteLine) of driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_EditControl1_gv']/tbody/tr[11]/td[3]")).Text to see the output in IE.

You might have to define a dedicated xpath for IE.

Upvotes: 3

Greg
Greg

Reputation: 5588

Assuming you're using java try getText()

String foo = driver.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_EditControl1_gv']/tbody/tr[11]/td[3]")).getText();

assertEquals(foo, "Selenium");

Upvotes: 1

Related Questions