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

Working principle and Environmental installation of selenium

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

Share

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

This article introduces the relevant knowledge of "the working principle and environmental installation of selenium". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Selenium is a web application automation tool, which simulates the real behavior of users by automatically operating the browser to click, enter, enter, return, and so on. How to understand and view the selenium project, selenium officials have a classic answer: "automated browsers, that's it. It's up to you to do what you want to do."

Selenium version:

There are currently three versions of selenium: selenium1.0,selenium2.0,selenium3.0. Among them, selenium1.0 has been officially abandoned. In order to keep up with the trend of the times, we learn selenium3.0 here, which is mainly composed of selenium webdriver and selenium Grid. Selenium webdriver is the operation of browsers, and selenium Grid is used for distributed automated testing.

Selenium advantages:

Open source, free

Cross-platform: Linux, windows, MAC

Cross-browser: Firefox, Chrome, IE, etc.

Support for multiple languages: Java, Python, JavaScript, C++, etc.

How selenium works:

1.selenium client (an automated test script written in python and other languages) initializes a service service and launches the browser driver chromedriver.exe through Webdriver

two。 Send the HTTP request to the browser driver through RemoteWebDriver, and the browser driver parses the request, opens the browser, and obtains the sessionid. If you operate on the browser again, you need to carry this id.

3. Open the browser, bind the specific port, and use the launched browser as the remote server of webdriver

4. After opening the browser, all selenium operations (access address, finding elements, etc.) are linked to remote server through RemoteConnection, and then use the execute method to call the _ request method to send a request to remote server through urlib3

5. The browser performs the corresponding action through the requested content

6. The browser then returns the result of the action to the test script through the browser driver.

Python environment installation

Install python, download address https://www.python.org/

Install it by default all the way after download, as long as you check it when adding the path. The python version used here is 3.7.4.

After the installation is complete, enter python under cmd under dos to verify that python is installed successfully:

As above, python is installed successfully.

Selenium environment installation

1.cmd to dos window, enter pip install selenium

Note: pip install selenium = = version number, you can download the corresponding version of selenium.

two。 After the installation is successful, enter python, enter shell mode, and enter from selenium import webdriver. No error indicates that the installation of selenium is successful.

3. You can also enter pip show selenium to view the installed version of selenium.

Chrome browser driver installation

1. Chromedriver download address: http://npm.taobao.org/mirrors/chromedriver/, download the corresponding driver according to your own Chrome version. The Chrome version of Xiao Fanhu is 76.0.3809, so let's download the 76.0.3809 driver together.

two。 Download the driver, extract it and put it in the python root directory.

Note: you need to configure the python directory to the environment variable, which is already configured when you install python. If it is not configured, please configure it yourself.

3. After the installation and configuration is complete, we run to see if the driver is installed successfully, and launch the Chrome browser, perfect!

Firefox installation driver

1. From selenium3 ×, Firefox47 version or above, you need to install geckodriver. Download address: https://github.com/mozilla/geckodriver/releases/, download by yourself according to the system.

two。 After the download is completed, extract it to the root directory of python:

3. After the installation and configuration is complete, write the code to see if the Firefox driver is installed successfully.

Open the firefox and open the Baidu page, indicating that the operation is successful.

This is the end of the introduction of "the working principle and Environmental installation of selenium". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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