The simplest example of Python selenium

Source: Internet
Author: User

Installing Selenium with Pip

Download Chromedriver, add in Path

#-*-coding:utf-8-*-   fromSeleniumImportWebdriver fromSelenium.common.exceptionsImporttimeoutexception fromSelenium.webdriver.support.uiImportWebdriverwait#available since 2.4.0Import Time#Create A new instance of the browser driverDriver = Webdriver. Chrome ()##可以替换为IE (), Firefox () Chrome ( )  #go to the Google home pageDriver.get ("https://www.google.com")    #find the element that's name attribute is Q (the Google search box)Inputelement = Driver.find_element_by_name ("Q")    #type in the searchInputelement.send_keys ("cheese!")  #submit the form. (although Google automatically searches now without submitting)Inputelement.submit ()#The page is ajaxy so the title is originally this:Print(Driver.title)Try:      #we have a to-wait for the page to refresh and the last thing this seems to being updated is the titleWebdriverwait (Driver). Until (LambdaDriver:driver.title.lower (). StartsWith ("cheese!"))        #You should see "cheese! -Google Search "    Print(Driver.title)finally: Driver.quit ()

The simplest example of Python selenium

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.