Python+selenium First Script

Source: Internet
Author: User

#coding =utf-8
Import time
From selenium import Webdriver

#打开浏览器
Driver=webdriver. Chrome ()
#最大化窗口
Driver.maximize_window ()
#设置隐式等待时间
Driver.implicitly_wait (8)
#打开百度
Driver.get ("https://www.baidu.com")
#定位到输入框并输入selenium
Driver.find_element_by_xpath ("//*[@id = ' kw ']"). Send_keys ("Selenium")
#定位到百度一下按钮并点击
Driver.find_element_by_xpath ("//*[@id = ' su ']"). Click ()
#等待2秒
Time.sleep (2)
#获取元素并检查是否有相应的文本存在
ele_string = Driver.find_element_by_xpath ("//*[@id = ' 1 ']/h3/a/em"). Text
if (ele_string = = "Selenium"):
Print U "Test succeeds, results match expected results! "

Driver.close ()

Python+selenium First Script

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.