Selenium_webdriver (python) gets the element attribute value, browser window control, page forward backward, Title/url print

Source: Internet
Author: User

[Python]View PlainCopy
    1. <span style="font-family:arial, Helvetica, Sans-serif;" ><span style="FONT-SIZE:18PX;" ># coding:utf-8 #这句是为了声明编码格式, be sure to have </span></span>
[Python]View PlainCopy
  1. <span style="FONT-SIZE:18PX;" > fromSelenium import webdriver #要想使用selenium function in the Webdriver, first bring the package in
  2. Import time #调入time function
  3. Driver=webdriver. Ie ()
  4. #选择浏览器, can be Firefox, Ie or Chrome, need to install the browser plugin before use;
  5. #driver是一个变量, you can pick up.
  6. Driver.get ("http://m.mail.10086.cn")
  7. The #mplicitly_wait () method implements the smart wait, which is equivalent to the set point in Uft, where the smart wait is 30 seconds
  8. Driver.implicitly_wait (+)
  9. driver.find_element_by_id ("ur"). Send_keys ("15610537527")
  10. #一个元素有若干属性id, name, (or otherwise), where the element is identified by ID, the ID of the input box is called UR,
  11. #我要在输入框里输入15610537527
  12. driver.find_element_by_id ("PW"). Send_keys ("15866584957")
  13. #网页对象操作:
  14. #. Click () Tap Object
  15. #?. Send_keys ("xxx") simulates key input on an object
  16. Clear () Clears the contents of the input box, for example, the Baidu input box has a "Please enter a keyword" message by default.
  17. # again, for example, our login box will have default information such as "Account" and "password" in general.
  18. # clear can help us clear this information.
  19. #. Submit () Submission Form
  20. #. Text gets the literal of the element
  21. # Get_attribute ("property name, such as name") to get the property value
  22. Data1 = Driver.find_element_by_class_name ("loading_btn"). Text
  23. Print "This element text is:"
  24. Print Data1
  25. Data2 = Driver.find_element_by_class_name ("loading_btn"). Get_attribute ("id")
  26. Print "The element id attribute value is:"
  27. Print Data2
  28. Driver.find_element_by_class_name ("Loading_btn"). Click ()
  29. #搜索的按钮的name called loading_btn, I need to click the button (click ()).
  30. Time.sleep (5) #休眠5秒
  31. Print Driver.title # prints the page title
  32. Print ": page access is successful! "  
[Python]View PlainCopy
  1. #将当前页面URL, print it out.
  2. Now_url = Driver.current_url
  3. Print Now_url
  4. Print "browser maximized:"
  5. Driver.maximize_window () #将浏览器窗口最大化显示
  6. Print "Set browser width 480, height 800 display:"
  7. Driver.set_window_size (480, )
  8. #操作浏览器访问网页后退
  9. Print "Back to Previous page:"
  10. Driver.back ()
  11. Time.sleep (1)
  12. #操作浏览器访问网页前进 (after back)
  13. Print "forward to Next page:"
  14. Driver.forward ()
  15. Time.sleep (2)
  16. #driver. Quit () #退出并关闭窗口的每一个相关的驱动程序
  17. Driver.close () #关闭当前窗口, pay attention to the difference between the above, select </span></span>

Selenium_webdriver (python) gets the element attribute value, browser window control, page forward backward, Title/url print

Related Article

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.