Using selenium in order to read emails on gmail - ajax

I'm using selenium-rc and I'm trying to click on a specific email on gmail in order to get into the email page. More specifically: on the gmail inbox, click on a email with a specific subject.
I can't find the correct xpath (none of the tags in the email part are links). Ideas?

This XPath should do the trick:
//div[#class = 'y6']/span[contains(., 'subject_here')]
... provided that you've first changed to the canvas_frame frame. Otherwise, it's unlikely it'll work at all. If you're not using Firebug to inspect the HTML, you really should as that's how I found out these values. Also, the Gmail structure changes fairly regularly, so that y6 class could change any day.
I haven't tested this, but this might work for you:
open http://gmail.com
// do the login stuff, click on login
waitForElementPresent canvas_frame
selectFrame canvas_frame
waitForElementPresent //div[#class = 'y6']/span[contains(., 'subject_here')]
clickAt //div[#class = 'y6']/span[contains(., 'subject_here')] 0,0
// do stuff you care about
Important: you have to use clickAt to cause Gmail to realize you're clicking. It doesn't work with just the simple "click" command.
By the way, we do this for our own internal monitoring of Gmail because it's been so unstable over the last few months. We're using my companies Selenium-based free monitoring service, which lets you run Selenium scripts to check performance and functionality of your site.

change gmail to basic html mode.

Is your app a Ruby on Rails one by chance? If so, email spec is a great way to test emails without haveing to mess around with Gmail: http://github.com/bmabey/email-spec

I used this command
clickAt | //table/tbody/tr/td[5]/div[#class='yW'] |
Click at the FROM field of first/recent/top most mail to go to mail detail page. // note: tr for first mail, tr[2] for second and so on.

Related

Is it possible to get another person's UI in Google Apps Script?

In Google Apps Script when you use the property: DocumentApp.getUi(), it gets the UI of the person who is using it. If you used DocumentApp.getUi().alert(), then it would send an alert to the person who is using the script. I am wondering if there is maybe a way to alert another person's UI in Google Apps Script and not the person who is using the script. Here is a sample of my code:
DocumentApp.getActiveDocument()
.removeViewer(userName.getResponseText())
.removeEditor(userName.getResponseText());
DocumentApp.getUi()
.alert("Your access is being removed.")
Now it would be wonderful and imagine all the possibilities if that were possible! Someone please help!
It is not possible to access the UI of any browser except the one which invoked the function. This is also why time driven triggers cannot display UI modals (they are executing nonlocally).

Error accessing Birthday variable using Watir during gmail sign-up

I am trying to create the gmail account through watir. As part of it while I am trying to select the birthday using div element I am unable to do.
I tried with the below one:
#ie.div(:text,'May').click
My system configurations:
IE-8
Windows-7
I've always disliked seeing the answers on here that say 'Why are you doing this?" or "Why would you want to do this?". So I'll just say "Don't do this!". I'm sure whatever issue you are facing can be resolved without automating the creation of gmail account.
If all you need is a unique gmail address then see the link below:
http://www.codestore.net/store.nsf/unid/BLOG-20111201-0411
Another option is https://mailinator.com/
As #titusfortner indicates, that element cannot be selected/clicked because it is not visible. Using watir-webdriver, this snippet makes the dropdown menu visible so its options can be selected:
b.div(title: "Birthday").when_present.click
b.div(text: "May").when_present.click
That being said, there are two other (read: larger) issues:
You won't be able to script your way past the captcha.
Google doesn't want you doing this. That's why the captcha is there, and they'll eventually block your IP if you consistently automate/script against them.
You can't click on the text of something that is not visible on the page. You first need to open the drop-down:
browser.span(id: 'BirthMonth').click
browser.div(text: 'May').click
b.element(:css, '#BirthMonth > div').click
b.element(:text, 'May').click
It works with Chrome and with Firefox also but not perfect

how can I add company logo in email in cakephp?

I have created page for mail template and set buttons for preview template also.
I have set image path from my local machine like,
src="/projectname/app/webroot/img/logo.JPG"
and when i preview that template it displays logo.
when using that template when i send mail image is not displayed in email.
So can anyone please tell me what could be the issuee or i am missing something like mime types?
Thanks,
This won't work. The email is opened in a client, what the hack would a path like "/projectname/app/webroot/img/logo.JPG" mean to that client? What is the domain?
You can either add a domain to the SRC like src="http://example.com/projectname/app/webroot/img/logo.JPG". But this won't be displayed by default, because it is a security risk.
Imagine spammers including images like src="http://example.com/feedback?id=12345" to each email, where ID is identifying each e-mail address the mail is sent to. Each client downloading this image will acknowledge the receiving of this e-mail, letting the spammers know you are reading their spam. Most e-mail clients explicitly ask you whether images referred to in the mail should be downloaded or not.
An alternative solution is to include each e-mail as an attachment to the e-mail, then you can refer to it as an "inline" image. This does no requires external connection and is less of a security risk, mostly allowed by default in clients.
I've google up a component that supposedly supports also inlining, but you might find others as well:
http://bakery.cakephp.org/articles/CraZyLeGs/2006/12/18/swiftmailer-component-tutorial
Within emails, you must use your full path, not a relative path. To do this easily in CakePHP, use the: FULL_BASE_URL constant with the HTML Helper like this:
<?php
echo $this->Html->image(
FULL_BASE_URL . $photo['Photo']['path'].$photo['Photo']['filename']
);
?>
(obviously this could be done in one line, but I broke it down for ease of reading on StackOverflow)
That's probably because when you test on your local machine, that path is fine. But if you send an email to yourself (say gmail) your browser will probably look for the image somewhere like http://mail.google.com/gmail/projectname/app/webroot/img/logo.JPG and will not find your image there.
So you'll need to set your image source to something like http://localhost/projectname/app/webroot/img/logo.JPG.
The email client needs the absolute path to the image; use the HTML helper to attach the full base:
<?= $this->Html->image("logo.JPG", array('fullBase' => true)) ?>
Note that the /projectname/app/webroot/img/ is not required when using the HTML helper.
If you are using CakePHP v1.2 or 1.3 (yes they are deprecated - but hey someone might find this useful) you will need to add a Content-ID header to the image to be attached to the email so you can refer to it via the cid when using it inline in the message. Open the email controller of the cake installation and add this line in the __attachFiles() method:
$this->__message[] = 'Content-ID: <' . basename($file) . '>';
You can then add the image in your template like so:
The attachfile method of email class in v1.2 & 1.3 only accepts paths and does not have the added functionalities of later version hence the "hack"

Rails 3.1 - Devise inserting address into subject line of confirmation email

I'm using rails 3.1 with Devise. When an account confirmation email goes out, it is received with the following subject line:
Subject: [["test13#test.com"]]MySite Account Confirmation Instructions
I've modified the corresponding entry in config/locals/devise.en.yml like this:
mailer:
confirmation_instructions:
subject: 'MySite Account Confirmation Instructions'
I don't want the '[["test13#test.com"]] in the email subject line. How can I get Devise to not put it there? BTW I really don't want to have to create some custom mailer that overrides Devises' stock mailer... Big extra bonus points for an answer that avoids anything to do with custom mailers. But if that is the only way, I need to know that too...
My guess is that the [["test13#test.com"]] should actually only show up in development mode, since that's the format of ActionMailer's DevelopmentMailInterceptor (see the notes in RailsCast 206)
The email address between brackets indicates the address to which the email would have been sent on production. It instead sends it to you at an email specified in your DevelopmentMailInterceptor.
The mail subject is generated in Devise::Mailers::Helpers.headers_for (source code here), so the most straightforward way would be monkey-patching this method.
This was a strange one... Had to reboot my Mac, after which the problem was gone.

How do I scrape google readers with mechanize (using cookies)

I'm trying scrape google readers but I've got problems...I wish to log in google readers and get a valid cookie...then try enter in this page:
'http://www.google.es/reader/atom/user/-/state/com.google/reading-list'
if my cookies work and I'm logged in I only need to put "user/-/" and it will enter inside my google reader's XML version....
It's in theory ... I log in inside google readers and it redirects ... then I copy my SID .... and I create a manual cookie using this and the google reader's API info
http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
name SID
domain .google.com
path /
expires 1600000000
with my cookie create I try enter inside:
'http://www.google.es/reader/atom/user/-/state/com.google/reading-list'
but it don't work .... I think I'm creating my cookie in a bad way but I read the API about CookieJar and Mechanize::Cookie, but I don't find any example about how to use it ... I've tried in different ways but none work ... please someone can help me about how use this cookie....
We do all our web scraping with iMacros (partly free/open source, partly commercial). That works well. No matter what you use, you need something that automates a real web browser. Other options are Selenium or Watir, although these are more geared towards web testing.

Resources