today, i would like present an basic script example of Python for Selenium Webdriver.
first line is a general Python code to use any printable string in utf-8 (# -*- coding: UTF-8 -*-)
next line is import selenium webdriver module (from selenium import webdriver)
create a Firefox driver and assigned it to a variable to use in following lines(driver = webdriver.Firefox())
set up implicit and explicit waits
after open browser, most of times it is useful to make maximize it(driver.maximize_window())
get() function is starting point !!! we use this function to open a webpage. After that, we print title element of page by “title” command. Don’t forget to close your driver after complete your operations(driver.close()) .
you can find complete working code at below:
# -*- coding: UTF-8 -*- from selenium import webdriver driver = webdriver.Firefox() driver.implicitly_wait(10) driver.set_page_load_timeout(10) driver.maximize_window() driver.get("http://www.mahsumakbas.net") print driver.title driver.close()