Automating Gmail reads, C# selenium2

1,341 views
Skip to first unread message

Samantha

unread,
Sep 29, 2011, 6:06:02 PM9/29/11
to Selenium Users
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





Paul Hammant

unread,
Sep 29, 2011, 6:13:37 PM9/29/11
to seleniu...@googlegroups.com
For software testing there are much easier 'email platforms' to script with Selenium.



Google change the Gmail interface so rapidly that you'll spend and age just trying to keep up.  Besides their terms of service suggests that you're not allowed to point things like Selenium at it (unless you are Google and using Selenium to test gmail before releasing updates).

- Paul






--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Samantha

unread,
Sep 30, 2011, 10:13:12 AM9/30/11
to Selenium Users
Thanks for the info.

I looked into the links and honestly I never knew those sort of things
existed.... cool stuff.

From what i have seen they sit between right behind the application
being tested. That isn't going to work for me.

We have several (say seven) different tesing enviornments, a demo env,
a release cantidate env and then several production enviornments
scattered in different datacenters around the world. Development
happens in one of three offices and each has their own sandbox that
may run the tests at some time.

My goal is to get as many people running the tests as possible. My
testing application is intentionally using only a web interface for
testing since that makes it trivial to change from platform to
platform with no configuration hassles. We have found that if there
is any excuse at all for someone to skip testing they tend to skip it
so we want to make things very easy.

In essence my testing application accepts one parameter, a base url
that will be prepended to any navigation during that testing session.
Point it at production, or point it a staging, or point it at local
host and the tests run fine.

Having one of the applications installed on each of the dozens of
possible test sites is not realistically going to happen .... I
suppose it could make this happen but hear me out.

If I can just stick to the web client for reading the emails the
configuration problems go away. In addition I can (theoretically)
open an email and teake a screenshot to show how the mailing renders
in various email clients. That would be big for us.

So back to the original question:
Why does the locator work on the IDE but not in webdriver.... same
browser, same page, same locator.

Again it's driving me nuts.
Thanks,
Samantha





On Sep 29, 6:13 pm, Paul Hammant <p...@hammant.org> wrote:
> For software testing there are much easier 'email platforms' to script with
> Selenium.
>
> One ishttp://fermata.gregheartsfield.com/ (https://github.com/scsibug/
> fermata )
>
> Others arehttp://www.icegreen.com/greenmail/andhttp://quintanasoft.com/dumbster/,
>
> Google change the Gmail interface so rapidly that you'll spend and age just
> trying to keep up.  Besides their terms of service suggests that you're not
> allowed to point things like Selenium at it (unless you are Google and using
> Selenium to test gmail before releasing updates).
>
> - Paul
>
Reply all
Reply to author
Forward
0 new messages