1. Control Window Size
Form Selenium Import Webdriver
Driver = Webdriver. Chrome ()
Driver.get ("http://www.baidu.com")
Print ("Set browser width 480, height 800 display")
Driver.set_window_size (480,800)
Driver.quit ()
2. Control browser forward, back
Form Selenium Import Webdriver
Frist_url = "Http://www.baidu.com"
Print ("Frist is%s"% (Frist_url))
Driver.get (Frist_url)
Second_url = "Http://www.sina.com"
Print ("Second is%s"% (Second_url))
Driver.get (Second_url)
Print ("Back to Frist_url%s"% (Frist_url))
Driver.back ()
Print ("Forward to Second_url%s"% (Second_url))
Driver.forward ()
Driver.quit ()
3. Browser Refresh
Driver.refresh ()
4. Operation of simple elements (Sina mailbox login)
Form Selenium Import Webdrver
Driver = Webdriver. Chrome ()
Driver.get ("http://mail.sina.com")
driver.find_element_by_id ("Freename"). Clear ()
driver.find_element_by_id ("Freename"). Send_keys ("[email protected]")
Time.sleep (2)
driver.find_element_by_id ("Freepassword"). Clear ()
driver.find_element_by_id ("Freepassword"). Send_keys ("")
Time.sleep (2)
Driver.find_element_by_class_name ("Loginbtn"). Click ()
Time.sleep (4)
Driver.quit ()
5. Submitting the form
. Click () can replace. Submit ()
6. Get the input frame size
Size = driver.find_element_by_id ("kw"). Size
Print (size)
7. Get the text of the element
Text = driver.find_element_by_id ("CP"). Text
Print (text)
8. Return the attribute value of an element
attribute = driver.find_element_by_id ("kw"). Get_attribute ("type")
Print (attribute)
9. Returns whether the element is visible
result = driver.find.element_by_id ("kw"). Displayed ()
Print (Result)
10. Enter text and clear text
browser.find_element_by_id ("kw"). Send_keys ("1234") enter ' 1234 ' on the KW element
browser.find_element_by_id ("kw"). Clear () Clears the information entered by the KW element
Web Automation 8-selenium Simple Operation method