Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Selenium Client Driver for Python (1)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

A brief introduction to Introduction

Introduce Selenium for Python.

1.selenium is used for web automated testing. Python2.7, 3.4 + and above are supported.

II. Selenium installation

You can install it online using pip install-U selenium, or you can download a source package, such as selenium-3.13.0.tar.gz, and install it using Python setup.py install after decompression.

Third, driver installation

Selenium needs to install a driver to open and close browsers, such as Firefox, need geckodriver, put this program in the Firefox installation directory, and configure Firefox's environment variables.

IV. Examples

1. Instance 0:

(1) Open a new Firefox browser

(2) Open the web page according to URL

From selenium import webdriver

Browser = webdriver.Firefox ()

Browser.get ('http://seleniumhq.org')

two。 Example 1:

(1) Open a new Firefox browser

(2) load the Yahoo home page

(3) find "seleniumhq"

(4) close the browser

From selenium import webdriver

From selenium webdriver.common.keys import Keys

Browser = webdriver.Firefox ()

Browser.get ('http://www.yahoo.com')

Assert 'Yahoo' in broeser.title

Elem = browser.find_element_by_name ('p')

Elem.send_keys ('seleniumhq' + Keys.RETURN)

Browser.quit ()

3. Example 2:

Selenium webdriver is also often used for basic testing of web applications.

Import unittest

From selenium import webdriver

Class GoogleTestCase (unittest.TestCase):

Def setUp (self): self.browser = webdriver.Firefox () self.addCleanup (self.browser.quit) def testPageTitle (self): self.browser.get ('http://www.google.com') self.assertIn (' Google', self.browser.title))

If name = 'main':

Unittest.main (verbosity=2)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report