How to launch and login to gmail account in Selenium using python

1,717 views
Skip to first unread message

santosh h s

unread,
Dec 30, 2010, 4:30:54 AM12/30/10
to Selenium Users
Hi All,
I am trying to launch gmail.com using selenium and python below is my
code

from selenium import selenium
import time
def sel_start():
global sel
sel = selenium("localhost", 4444, "iexplore", "http://
www.gmail.com")
sel.start()
sel.open("http://www.gmail.com")
time.sleep(5)
sel.wait_for_page_to_load("30000")

def tearDown(sel):
sel.stop()

sel_start()
tearDown(sel)

but his doesn't work and throws me an error.i thin this is because
when i launch http://www.gmail.com it redirects to https://

Please help me how to handle this

delphin

unread,
Dec 30, 2010, 5:05:56 PM12/30/10
to Selenium Users
rom selenium import selenium
import unittest, time, re, sys, bdata, blib, types, utility
Home_URL="https://www.google.com/"
New_userName=""
New_password=""

class Clean_gmail(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost",
4444,bdata.BrowserType,Home_URL)
self.selenium.start()

def test_clean_gmail(self):
sel = self.selenium
sel.open("/accounts/")
sel.click("link=Gmail")
sel.wait_for_page_to_load("30000")
try: self.failUnless(sel.is_text_present("Welcome to Gmail"))
except AssertionError, e:
self.verificationErrors.append(str(e))
sel.select_window("null")
sel.type("Email", bdata.gmailEmail)
sel.type("Passwd", bdata.gmailPassword)
sel.click("signIn")
sel.wait_for_page_to_load("50000")


if __name__ == "__main__":
unittest.main()


On Dec 30, 1:30 am, santosh h s <santosh.s...@gmail.com> wrote:
> Hi All,
> I am trying to launch gmail.com using selenium and python below is my
> code
>
> from selenium import selenium
> import time
> def sel_start():
>     global sel
>     sel = selenium("localhost", 4444, "iexplore", "http://www.gmail.com")
>     sel.start()
>     sel.open("http://www.gmail.com")
>     time.sleep(5)
>     sel.wait_for_page_to_load("30000")
>
> def tearDown(sel):
>     sel.stop()
>
> sel_start()
> tearDown(sel)
>
> but his doesn't work and throws me an error.i thin this is because
> when i launchhttp://www.gmail.comit redirects to https://

santosh h s

unread,
Dec 31, 2010, 12:58:37 AM12/31/10
to seleniu...@googlegroups.com
how to archive this using http://gmail.com instead of going from Google.com

--
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.




--
Regards,
Santosh

Jayakumar C

unread,
Dec 31, 2010, 2:49:09 AM12/31/10
to seleniu...@googlegroups.com
@santosh,

open() itself has implicit wait and no need of waiting again for page load.
The following raw Se+python script working fine for me to Signin gmail.


import selenium
import time
TIMEOUT=30

sel=selenium.selenium("localhost",4445,"*iexplore","http://www.gmail.com")
sel.start()
sel.window_focus()
sel.window_maximize()
sel.open("http://www.gmail.com")
sel.type("css=#Email", "your username")
sel.type("css=#Passwd", "your password")
sel.click("css=#signIn")

#Wait for  "Sign out" link
#You can wrap this portion into a method.(i.e)wait_for_element_present()
for i in range(TIMEOUT):
    try:
        if sel.is_element_present("link=Sign out"): break
    except: pass
    time.sleep(1)
else: raise "Timeout:Element not found..."

sel.click("link=Sign out")

#Wait for  user name text box
for i in range(TIMEOUT):
    try:
        if sel.is_element_present("css=#Email"): break
    except: pass
    time.sleep(1)
else: raise "Timeout:Element not found..."

sel.close()
sel.stop()


Hope this helps ...



--
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.




--
Jayakumar

santosh h s

unread,
Dec 31, 2010, 4:47:27 AM12/31/10
to seleniu...@googlegroups.com
with the below code i get an error please refer the attachment for the erro.
i guess error is because on launching http://gmail.com it automatically redirects to https://
Regards,
Santosh
error.png

Jayakumar C

unread,
Dec 31, 2010, 6:09:01 AM12/31/10
to seleniu...@googlegroups.com
That Se+py script working fine for me in the following environment.
OS : Windows Server 2003 (64bit)
IE  :7
Se-Sever : RC.1.0.3

You can try to run the script after adjusting/relaxing the IEs security settings.
Tools->Internet options->Advanced.
(e.g)
un-checking  "warn if changing between secure and not secure mode"

If nothing helps, you can try to open the complete url.
https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2

Jayakumar C

unread,
Dec 31, 2010, 6:51:52 AM12/31/10
to seleniu...@googlegroups.com
You can also try to use the open() method with True as a second parameter to  ignore the response code.

sel.open("http://www.google.com",True)
--
Jayakumar

Freddy Vega

unread,
Dec 31, 2010, 9:55:11 AM12/31/10
to Selenium Users
@Santosh - what is it that you're trying to test within the Gmail
application?

Can you achieve the same thing using imaplib?


On Dec 31, 4:47 am, santosh h s <santosh.s...@gmail.com> wrote:
> with the below code i get an error please refer the attachment for the erro.
> i guess error is because on launchinghttp://gmail.comit automatically
> redirects to https://
> > On 30 December 2010 01:30, santosh h s <santosh.s...@gmail.com> wrote:
>
> >> Hi All,
> >> I am trying to launch gmail.com using selenium and python below is my
> >> code
>
> >> from selenium import selenium
> >> import time
> >> def sel_start():
> >>    global sel
> >>    sel = selenium("localhost", 4444, "iexplore", "http://
> >>www.gmail.com")
> >>    sel.start()
> >>    sel.open("http://www.gmail.com")
> >>    time.sleep(5)
> >>    sel.wait_for_page_to_load("30000")
>
> >> def tearDown(sel):
> >>    sel.stop()
>
> >> sel_start()
> >> tearDown(sel)
>
> >> but his doesn't work and throws me an error.i thin this is because
> >> when i launchhttp://www.gmail.comit redirects to https://
>
> >> Please help me how to handle this
>
> >> --
> >> 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<selenium-users%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/selenium-users?hl=en.
>
> > --
> > Jayakumar
>
> > --
> > 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<selenium-users%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/selenium-users?hl=en.
>
> --
> Regards,
> Santosh
>
>  error.png
> 441KViewDownload

santosh h s

unread,
Dec 31, 2010, 2:44:49 PM12/31/10
to seleniu...@googlegroups.com
actually i am want to write a script for login to watch.slingbox.com which is similar to gmail.com that's why i asked for gmail.
i scripting in python for functional testing of this site using selenium an dpython

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.




--
Regards,
Santosh
Reply all
Reply to author
Forward
0 new messages