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

How to build Python+Selenuim Automation Environment

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "how to build Python+Selenuim automation environment". In daily operation, I believe many people have doubts about how to build Python+Selenuim automation environment. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to build Python+Selenuim automation environment". Next, please follow the editor to study!

1. The system environment used this time is the latest Windows 10 17134 system.

two。 The Python version used this time is 3.4.4. The reason for using this version is that the XP system will not be supported after 3.5, but I need a XP environment, so I have been using version 3.4, Python download address: https://www.python.org/downloads/

3. The Selenium version used this time is the latest 3.13. If only one version of Python is installed on your computer, you can install it directly using the command line:

Python-m pip install selenium

If you have multiple versions of Python installed on your computer and renamed using the "flexible switching of multiple versions of Python in use" that I mentioned earlier, please use the corresponding command line version to install, such as:

Python34-m pip install selenium

If you fail to install this command, you can try it a few more times, because the link is a foreign site, so you know.

Of course, you can also download the whl file from the official website to install it. The command line for installing the whl file is:

Python-m pip install selenium-xxx.whl

Download address of whl file:

Https://pypi.org/project/selenium/#files

4. The browser version used this time is the latest Google Chrome 68.0.3440.84 (official version) (64-bit), which can be downloaded by FQ or through "360 Software Housekeeping".

Official download address:

Https://www.google.com/chrome/

5. The ChromeDriver version used this time is the latest 2.41. Please note that different ChromeDriver versions support different Chrome versions. It is recommended that both of them be updated to the latest to avoid repeated trampling.

If you are not using Chrome, please install the Driver of the corresponding browser. All Driver addresses can be found here: http://selenium-python.readthedocs.io/installation.html#drivers

The download address of ChromeDriver is: https://sites.google.com/a/chromium.org/chromedriver/downloads

The Driver of the same browser also distinguishes different system versions. For example, the file of ChromeDriver on Windows platform is chromedriver_win32.zip.

6. The downloaded ChromeDriver is a zip package. In the Windows version, there is a chromedriver.exe. Please note:

The decompressed chromedriver.exe full path needs to be added to the system environment variable path.

After path modification, the command line tool needs to be restarted to take effect.

You can check whether the addition is successful by typing the command path on the command line

Another trick is to drop chromedriver.exe directly into the scripts directory under the python installation directory. If you're not mistaken, this directory has previously added environment variables, so you don't need to modify them again.

7. If you strictly follow the above steps, the basic environment should be ready. Let's start writing the first script according to the official tutorial:

#-*-coding: utf-8-*-

"" selenium webdriver test demo "

Import time

From selenium import webdriver

Def test (): driver = webdriver.Chrome () driver.get ('http://www.google.com/xhtml') time.sleep (2) # Let the user actually see something! Search_box = driver.find_element_by_name ('q') search_box.send_keys ('ChromeDriver') search_box.submit () time.sleep (5) # Let the user actually see something! Driver.quit ()

If _ _ name__ = ='_ _ main__': test ()

8. The effect after running is as follows. If you see the prompt "Chrome is under the control of automated testing software", the environment is prepared correctly.

9. At this point, the Selenium automation environment has been successfully built, and we can carry out the journey of selenuim automation according to webdriver api.

At this point, the study on "how to build a Python+Selenuim automation environment" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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