Import module:
From selenium import Webdriver
From selenium.common.exceptions import nosuchelementexception
Select browser: Driver = webdriver. Firefox ()
Open URL: driver.get ("http://www.baidu.com")
wait: driver.implicitly_wait (30)
Driver.set_page_load_timeout (30)
Driver.set_script_timeout (30)
Close Browser: driver.quit ()/driver.close ()
forward / reverse: Driver.forward ()/driver.back ()
Refresh: Driver.refresh ()
returns the current page title: Driver.title
returns the current page URL: Driver.current_url
returns all the windows of the current browser: Driver.window_handles
returns the window handle of the current browser: Driver.current_window_handle
Select window: driver.switch_to_window ( "window_name ")
dialog box action: Driver.switch_to_alert () # Select Window Object
Accept () # Click to confirm
Dismiss () # Click Cancel
Text # get literal value
send_keys ( " ") #
anchor Element (single): driver.find_element (by="ID", Value=none)
IdPositioning: driver.find_element_by_id ( "id_name ")
name positioning: driver.find_element_by_name ( "name ")
CssPositioning: driver.find_element_by_css_selector ("#foo")
XpathPositioning:Driver.find_element_by_xpath (“//select[@id = '
link positioning: driver.find_element_by_link_text (U " link ")
tag positioning: driver.find_element_by_tag_name ( "foo ")
Intercept Current page: driver.get_screenshot_as_file ('/screenshots/foo.png ')
Read (601)| Comments (0)
Selenium Webdriver+python Basic operation