selenium python tutorial chapter 1

1. Installation

insert image description here

1.1. Installation

Selenium Python bindings provide a simple API that lets you write functional/validation tests using Selenium WebDriver. Through the API of Selenium Python, you can use all the functions of Selenium WebDriver very intuitively.

Selenium Python bindings allow you to use Selenium WebDrivers (Selenium web drivers) like Firefox, IE, Chrome, Remote, etc. using a very concise and convenient API. Currently supported versions are 2.7, 3.2 and above.

This article is used to explain the API of Selenium 2 WebDriver, this document does not include the documentation of Selenium 1 / Selenium RC.

1.2. Download Python bindings for Selenium

You can download the selenium support library from the official library of PyPI. Click here to download. Of course, a better way is to use the pip command to install the selenium package. The pip command is included in the _ of Python3.5 标准库 <https://docs.python.org/3.5/installing/index.html>. Using pipthe command, you can install selenium like this:

pip install selenium

1.3. Windows installation

1) Install Python3.5: Official download page .

Windows+R2) Click Run (or ) Enter from the start menu cmd, and then execute the following command to install:

C:\Python35\Scripts\pip.exe install selenium
  1. Download the browser driver

Determine the browser you are using and download the corresponding driver. Common browser driver download addresses are as follows:

browser download link
Chrome https://sites.google.com/chromium.org/driver/
Edge https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Firefox https://github.com/mozilla/geckodriver/releases
Safari https://webkit.org/blog/6900/webdriver-support-in-safari-10

The downloaded driver can be placed in the project directory, or the path of the driver can be added to the system path environment variable.
If FireFox is not installed on the computer, even if the driver is downloaded, an error will be reported when running because the browser program is not installed on the computer

Now you can run the test script using Python. For example: if you created a basic example of selenium and saved it in C:my_selenium_script.py, you can execute it as follows:

C:\Python35\python.exe C:\my_selenium_script.py

1.4 Download Selenium Server

Selenium server is a JAVA program, and Java Runtime Environment (JRE) 1.6 or higher is the recommended operating environment.

You can download the 2.x Selenium server from the download page. The file looks like this: selenium-server-standalone-2.xxjar. You can download the latest version of the 2.x server.

If you haven't installed Java Runtime Environment (JRE), you can download it here. If you have a GNU/Linux system, and coincidentally, you still have root privileges, you can also use operating system instructions to install JRE.

If you put javathe command in PATH (environment variable), use the following command to install:

java -jar selenium-server-standalone-2.x.x.jar

Of course, just 2.x.xreplace it with the actual version you downloaded.

If you are not a root user or you have not put JAVA in PATH, you can use the absolute path or relative path to use the command. This command looks like this:

/path/to/java -jar /path/to/selenium-server-standalone-2.x.x.jar

Guess you like

Origin blog.csdn.net/captain5339/article/details/131104943