API automates native browser for testing
https://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
Selenium IDE - Firefox plugin, record script and playback, export Remote Control / WebDriver script;
Selenium Server - to execute the scripts (RemoteControl or WebDriver)
IE Driver Server - to run IE scripts
Selenium Client & WebDriver language binding - language specific client drivers
Other, 3rd party driver and plugins
Very easy, see download and installation site
Not just a time saver, but also excellent way to learn API
Install - follow instruction
Run - "Tools" -> Selenium IDE
Record - just start recording and do the browsing, watch action recorded and appears
The RemoteWebDriver interface defines common behaviour of various sub-classes for different browsers
Some frequently used methods:
cookie handling...
back() / forward() / refresh()
close()
execute(driver_command...)
find_elements_by....
get(url)
get screenshot
implicitly_wait(time_to_wait) for loading and element to appear
window size handling
page_source, get the source of page
not to load pictures, etc.
firefoxProfile = FirefoxProfile()
firefoxProfile.set_preference('permissions.default.stylesheet', 2)
firefoxProfile.set_preference('permissions.default.image', 2)
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so','false')
driver = webdriver.Firefox(firefoxProfile)
driver.implicitly_wait(30)
xpath seems to be the most powerful expression to find any element in HTML texts
driver.find_elements_by_xpath("//td[contains(@background,'../images/jiatu01.jpg') and contains(@height,'103') and contains(@width,'926')]/table[contains(@height,'133') and contains(@width,'902')]/tbody/tr/td[contains(@class,'lan12xi')]")
Here's some xpath quick reference: http://www.mulberrytech.com/quickref/xpath2.pdf http://scraping.pro/res/xpath-cheat/XPath-2.pdf
Best, open Firefox Developer Tools, evaluate xpath expression with $x("//xpath/expression"), see https://developer.mozilla.org/en-US/docs/Tools/Web_Console
Find a link
driver.find_elements_by_link_text(str(page))[-1].click()
By css class name
driver.find_elements_by_class_name