<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Yak Shaving &#187; webdriver</title>
	<atom:link href="http://www.chrishannam.co.uk/category/google/webdriver/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrishannam.co.uk</link>
	<description>just me</description>
	<lastBuildDate>Wed, 14 Dec 2011 12:13:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>WebDriver for logging into Twitter</title>
		<link>http://www.chrishannam.co.uk/2009/06/webdriver-for-logging-into-twitter/</link>
		<comments>http://www.chrishannam.co.uk/2009/06/webdriver-for-logging-into-twitter/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 13:05:15 +0000</pubDate>
		<dc:creator>channam</dc:creator>
				<category><![CDATA[webdriver]]></category>

		<guid isPermaLink="false">http://www.chrishannam.co.uk/?p=224</guid>
		<description><![CDATA[No real reason for choosing Twitter apart from its cool . The code below uses unittest to run. It creates a new WebDriver object and users it to fetch http://twitter.com and submit a username and password. Once the details are added it &#8220;clicks&#8221; the &#8220;Sign In&#8221; button to login into Twitter. #!/usr/bin/env python import unittest [...]]]></description>
			<content:encoded><![CDATA[<p>No real reason for choosing Twitter apart from its cool <img src='http://www.chrishannam.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>The code below uses unittest to run. It creates a new WebDriver object and users it to fetch http://twitter.com and submit a username and password. Once the details are added it &#8220;clicks&#8221; the &#8220;Sign In&#8221; button to login into Twitter.</p>
<pre name="code" class="python">
#!/usr/bin/env python

import unittest
import logging
from webdriver_firefox.webdriver import FirefoxLauncher
from webdriver_firefox.webdriver import WebDriver

class TwitterTests (unittest.TestCase):

    def test_login_twitter(self):
        driver = WebDriver()
        driver.get("http://twitter.com")

        # find our elements - the html on the page with same ids
        username_element = driver.find_element_by_id('username')
        password_element = driver.find_element_by_id('password')

        # use this to toggle the remember me box
        remember_me_element = driver.find_element_by_id('remember')

        # type into the boxes
        username_element.send_keys('yourusername')
        password_element.send_keys('yourpassword')
        remember_me_element.toggle()

        # click Sign In and we should be logged in
        driver.find_element_by_id('signin_submit').click()

       # check that the title of the page is correct to see if we logged in
        self.assertEqual(driver.get_title(), 'Twitter / Home')

        # Extract from the html using xpath to find username and updates of the people on the screen
        updates = driver.find_elements_by_xpath("//span[@class='entry-content']");
        user = driver.find_elements_by_xpath("//a[@class='screen-name']");

        # display in the terminal the name and the update
        for i,update in enumerate(updates):
            print user[i].get_text() + ": " +update.get_text()

        # uncomment the following to close the window and finish
        #driver.quit()

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    unittest.main()
</pre>
<p>The docs are not great for WebDriver but reading the source is pretty simple. Being able to mentally parse Java to Python is also a big advantage!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishannam.co.uk/2009/06/webdriver-for-logging-into-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

