Selenium browser-based operations (Python)

Source: Internet
Author: User

To start testing, you need to know what browser to test first. How to install the driver for the browser, have talked before.

The second is to know how to open the browser, this, in the previous code, also reflected, but did not delve into. Let's talk about the browser operation.

 fromSeleniumImportWebdriver fromTimeImportSleep#Open BrowserDriver =Webdriver. Firefox ()#Open Web pageDriver.get ("https://www.baidu.com/")#set the current browser width height to 200,300Driver.set_window_size (" $"," -") Sleep (2)#Browser MaximizationDriver.maximize_window ()#Print Browser titlePrint(Driver.title)#print the current URLPrint(Driver.current_url)#Browser forward backDriver.find_element_by_name ("tj_trnews"). Click () Driver.back () Sleep (2) Driver.forward () Sleep (2)#Exit BrowserDriver.quit ()
 fromSeleniumImportWebdriverImport Time#close a browser windowDriver =Webdriver. Firefox () Driver.get ("http://home.firefoxchina.cn/") Driver.find_element_by_css_selector ("a[title= ' Micro blog '"). Click ()#switch to the window you want to closeDriver.switch_to.window (driver.window_handles[-1])#Close the current windowDriver.close ()

The problem of switching Windows is introduced in the Selenium switch window

Selenium browser-based operations (Python)

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.