Wednesday 30 November 2011

Hello World! WebDriver with Python on Win 7

You will need:
1.  python-2.7.2.msi (Python installer)
        After installing, be sure to add  installed directory to your PATH environment.
2. setuptools-0.6c11.win32-py2.7.exe (Package installer)
       After installing, be sure to add  directory that contain easy_install.exe to your PATH environment variable. In my case it was C:\Python27\Lib\site-packages.






3. chromedriver.exe (Need this for automating in Chrome browser)
       Download chromedriver_win_16.0.902.0.zip from http://code.google.com/p/chromium/downloads/list . Remember the location of the chromedriver.exe


4. Text editor(any)
       I am using SciTE. Download it from http://www.scintilla.org/SciTEDownload.html
Start the application, select python from language. To run the code press F5.




Steps: 
1. Install Selenium. In Command Prompt write easy_install selenium
2. Start writing code


In Chrome:



from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome("E:\QA\Resource\WEBDRIVER\chromedriverserver\chromedriver.exe")
driver.get("https://www.google.com")
elem = driver.find_element_by_name("q")
elem.send_keys("Hello World!")

Here 

E:\QA\Resource\WEBDRIVER\chromedriverserver\chromedriver.exe  was my location of 
chromedriver.exe.


In Firefox:



from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("https://www.google.com")
elem = driver.find_element_by_name("q")
elem.send_keys("Hello World!")

In Internet Explorer:



from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Ie()
driver.get("https://www.google.com")
elem = driver.find_element_by_name("q")
elem.send_keys("Hello World!")

Be sure that checked Enable Protected Mode. To do that go to Internet option, select Security tab.



4 comments:

  1. I am not sure the place you are getting your information, however good topic. I needs to spend some time studying more or understanding more. Thank you for wonderful information I was in search of this info for my mission.

    Selenium Training in Chennai

    ReplyDelete
  2. Thanks for sharing the valuable information here. So i think i got some useful information with this content. Thank you and please keep update like this informative details.

    Back to Original

    ReplyDelete
  3. from my experience point of view score is must and needful for everygraduate students. thanks for valuable article.
    Germany Education Consultants in Chennai

    ReplyDelete
  4. Good blog post which provided a interesting information hello world webdriver with python.keep updating...
    SEO Companies in India

    ReplyDelete