Python selenium Webdriver Getting started basic operations

Source: Internet
Author: User

Python selenium Webdriver Getting started basic operations

No reprint without the permission of the author!

 fromSeleniumImportWebdriverImportTimedriver=Webdriver. Chrome () Driver.get ('http://www.baidu.com')#Enter Baidu homepageDriver.maximize_window ()#window MaximizationTime.sleep (1) Driver.set_window_size (480,600)#Window Size ChangeTime.sleep (1) Driver.maximize_window () Time.sleep (1) Driver.set_window_size (500,700) Time.sleep (1) Driver.maximize_window () Time.sleep (1) Driver.set_window_size (600,800) Time.sleep (1) Driver.maximize_window () Time.sleep (1) Driver.set_window_size (700,1000)Print'#窗口大小变化结束'Time.sleep (2) driver.find_element_by_id ('kw'). Send_keys ('Selenium')#Input keyword SeleniumTime.sleep (1) driver.find_element_by_id ('su'). Click ()#go to Selenium pageTime.sleep (3) Driver.find_element_by_xpath ("//*[@id = ' 1 ']/h3/a"). Click ()Print'Enter Selenium official website'Time.sleep (3) Driver.find_element_by_link_text ('Functional Automation Test tool--selenium'). Click ()#positioning by anchor textTime.sleep (10) Windows=Driver.window_handlesdriver.switch_to_window (windows[1])#Toggle Window#Driver.refresh ()Driver.maximize_window () time.sleep (2) driver.close () Windows=Driver.window_handlesdriver.switch_to_window (windows[1])#Toggle WindowTime.sleep (2) driver.close () Windows=Driver.window_handlesdriver.switch_to_window (windows[0])#Toggle WindowContent=driver.find_element_by_xpath ("//*[@id = ' 1 ']/div[2]"). Text#print out this part of the contentPrintContentdriver.back ()Print'back to Baidu homepage'Time.sleep (2) Driver.forward ()Print'go to the next page'Time.sleep (5) Driver.find_element_by_xpath ("//*[@id = ' u ']/a[2]"). Click () Driver.find_element_by_xpath ("//*[@id = ' wrapper ']/div[4]/a[1]"). Click ()#handling elements with drop-down boxesTime.sleep (1) Driver.find_element_by_xpath ("//*[@id = ' Gxszbutton ']/a[1]"). Click () time.sleep (1) Driver.switch_to_alert (). Accept ()#Handling Warning Pop -up windowsTime.sleep (2)Print'Handle the warning pop-up window.'JS="var q=document.documentelement.scrolltop=10000"driver.execute_script (JS)#handle the scroll bar on the rightTime.sleep (3)Print"scroll bar on the right to the lowest point"driver.close ()

You can try this code, the absolute run of the pass!

Python selenium Webdriver Getting started basic operations

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.