Selenium 2 and Python - ok so Windmill is my new favorite.

home | blog | Teh Internet | guest blog |rants | placeholder | political | projects | Gwen and Liam | Citadel patched | Tools | Scouts


- Careful Chrome users, this search box might be "Not secure"




Update 4: - Have not tried it yet, but Splinter looks easy as well:
https://github.com/cobrateam/splinter/blob/master/docs/index.rst
http://splinter.readthedocs.org/en/latest/#
Update 3: You should probably try to use requests first!

Update 2: Turns out Windmill is mostly part of the old Chandler server stuff, so mostly getting crufty... Back to Selenium 2.

Update: Windmill is more fun now http://pypi.python.org/pypi/windmill/


Scripting password changes in webmail using Python and Selenium 2
Selenium is pretty cool!
from selenium import webdriver
import sys
import os

wdrv = webdriver.Firefox()
wdrv.get("http://webmail.domain.example")

# first, log in to the webmail interface
unamefield = wdrv.find_element_by_name("username")
unamefield.send_keys("user")
pwdfield = wdrv.find_element_by_name("passwd")
pwdfield.send_keys("current_password")
pwdfield.submit()

# now go to the change password link
wdrv.get("http://webmail.domain.example/passwordchange.php")

# pop over to the correct frame to find the form fields...
wdrv.switch_to_frame("password_change_frame")

# You can peek at the source - to see what is going on
# if you are interactive mode and just writing code (ha ha php!)
#print wdrv.get_page_source()
password = wdrv.find_element_by_name("password")
password.send_keys("new_password")
confirm_password = wdrv.find_element_by_name("confirm")
confirm_password.send_keys("new_password")
confirm_password.submit()
# if you want a screenshot of the data after submit, you can do it with:
wdrv.get_screenshot_as_file("test.png")
wdrv.quit()

One gotcha. If your form has an item named "submit", this will fail. Find the item named "submit" and pass it .click()
So for example, instead of doing .submit() on the pwdfield, do this:
subbtn = wdrv.find_element_by_name("submit")
subbtn.click()

Also, for quick testing, you can get screenshots (might want to use time.sleep(seconds) if loading data from a db)...
wdrv.get_screenshot_as_file('./ssfilename.png')


This looks interesting!: http://readthedocs.org/docs/selenium-python/en/latest/



[æ]