Web applicaiton testing with Selenium and Python:
1: How to install selenium for python:
1a: check if you have easy_install [ for python pkg installation] in your system, if not install the same.
1b: sudo easy_install selenium
[or] you can try pip to install the same [pip install -U selenium ]
[or] download the file form PyPi and use: python setup.py install
2: [ Start Firefox and visit to www.google.com ]
In [1]: from selenium import webdriver
In [2]: browser = webdriver.Firefox()
In [3]: browser.get('http://www.google.com/')
====== Trying for auto login ==========
from selenium import webdriver
#Following are optional required
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
baseurl = "http://www.irctc.co.in/"
username = "yourUsername"
password = "yourPassword"
xpaths = { 'usernameTxtBox' : "//input[@name='username']",
'passwordTxtBox' : "//input[@name='password']",
'submitButton' : "//input[@name='login']"
}
mydriver = webdriver.Firefox()
mydriver.get(baseurl)
#mydriver.maximize_window()
#Clear Username TextBox if already allowed "Remember Me"
#mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).clear()
#Write Username in Username TextBox
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).send_keys(username)
#Clear Password TextBox if already allowed "Remember Me"
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).clear()
#Write Password in password TextBox
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).send_keys(password)
#Click Login button
mydriver.find_element_by_xpath(xpaths['submitButton']).click()
########## External #####
Youtube video:
Selenium For Pythonistas: https://www.youtube.com/watch?v=2OA941RLbmU
http://selenium-python.readthedocs.org/
No comments:
Post a Comment