Web Automation 8-selenium Simple Operation method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.