Selenium automated testing environment installation tutorial

0X00 Preface:

Selenium is a widely used tool for web application testing. It provides a powerful set of APIs for simulating user interaction with a web browser. Here is a brief introduction to Selenium:

  1. Function: Selenium can automate operations on various web browsers, such as clicks, inputs, selections, etc. It can simulate user behavior in the browser to achieve automated testing and web page data extraction.

  2. Compatibility: Selenium supports a variety of browsers, including mainstream browsers such as Chrome, Firefox, and Safari, allowing developers to test and develop on different browsers.

  3. Supports multiple programming languages: Selenium provides support for multiple programming languages, such as Java, Python, C#, etc. Developers can choose the appropriate programming language for development according to their preferences and project needs.

  4. Flexibility: Selenium provides a rich API to meet different levels of automation needs. It supports positioning elements, processing page pop-ups, processing JavaScript, processing Frames, etc., and has strong flexibility and scalability.

  5. Integration: Selenium can be integrated with other testing frameworks and tools, such as TestNG, JUnit, Jenkins, etc., making the collection, running and reporting of test results more convenient and efficient.

It should be noted that although Selenium is a powerful tool, you need to carefully consider the scenario and purpose of automated testing when using it. At the same time, when using Selenium to extract web page data, you need to comply with relevant laws and regulations and the website's terms of use.

0X01selenium environment installation tutorial:

1. Install the Python environment (not demonstrated here)
2. pip install selenium under cmd command2.48.0 download selenium2.48.0 (If you do not add the following version number, the latest selenium version will be installed by default)
3. Enter pip show selenium under the cmd command to display the version number.
Insert image description here

4. Install pycharm community version (if you have the ability, you can also install the professional version v )

Download link address:
https://www.jetbrains.com/pycharm/download/download-thanks.html?platform=windows&code=PCC
After the download is completed, enable pycharm, select the python running path –> create a new test.py, and test in Enter from se in the code programming area to check whether it is successful.

0X02 browser driver installation tutorial:

1. Google Chrome: Download Google Chrome or if Google Chrome already exists on your computer, you can check the version of Google Chrome first.
Insert image description here

Visit the chromedriver website to download the version corresponding to Google Chrome,
http://chromedriver.storage.googleapis.com/index.html
Insert image description here

The latest version here is version 114, and my Google Chrome is version 117. The chromedriver official website has not updated the latest version, so I use Firefox as a demonstration below.

After installing Firefox, go to the Firefox driver website to download the latest driver
https://github.com/mozilla/geckodriver/releases
Insert image description here

After downloading and decompressing, place the driver under the Python interpreter directory. If you don’t know where the Python interpreter is, you can open cmd and enter where python
Insert image description here
Insert image description here

Place the interpreter below to complete the installation.

0X03 Run selenium to perform automated testing:

Open pycharm and start writing code. The code is as follows:
Insert image description here

After running, a simple automated process for opening Baidu can be completed.

Guess you like

Origin blog.csdn.net/qq_50377269/article/details/133562093