I have a mystery... I have an xpath locator that works in selenium IDE
but does not work in selenium2 with C# and I cant figure out why.
Ultimately what I am trying to do is to be able to confirm that my
system is sending mails (later I'll want to see how they render).
So I have been following my "standard process":
1) Use the IDE and firebug to determine a good locator
2) plug the locator into C# and write my tests there.
The problem is that the locator does not work in selenium2... I have
no idea why.
To duplicate my issue:
1) Create and send an email to a gmail account with the subject = fred
and the body = barney from any mail client
2) open the gmail acount and validate that the email was received.
3) open the email with the subject of "fred" in gmail.
4) I used selenium ide to figure out a good locator for the subject
(that I need to click later to open the email)
If the mailing has been read this locator works in the IDE xpath=//
span[contains(text(),'fred')]
If the mailing is unread the locator looks like this xpath=//
b[contains(text(),'fred')] {note the span in place of the b tag}
so since we opened the mailing the correct locator to use is xpath=//
span[contains(text(),'fred')]
-so far so good-
Now if I code it in c# it looks like this (this code runs after you
set the username and password to valid values but it's simplified for
this example... don't think I have hardcoded locators or sleeps in my
real code)
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("
https://www.gmail.com"); //
login page
driver.FindElement(By.Id("Email")).SendKeys("gmail account
name");
driver.FindElement(By.Id("Passwd")).SendKeys("gmail
password");
driver.FindElement(By.Id("signIn")).Click();
System.Threading.Thread.Sleep(2000); //pause for page to
load
//now navigate to the inbox
driver.Navigate().GoToUrl("
https://mail.google.com/mail/?
shva=1#inbox");
System.Threading.Thread.Sleep(2000); //pause for page to
load
//try to get the click the mailing with the subject of
fred
//this should only work when we are clicking on a mailing
that has already been read
driver.FindElement(By.XPath("//
span[contains(text(),'fred')]")).Click();
This errors on the last line saying:
Unable to locate element: {"method":"xpath","selector":"//
span[contains(text(),'fred')]"}
... Even though this same locator works in the IDE... never had this
happen before.
Please help. This is driving me buggy.
Thanks
Samantha