Super fun Selenium python installation and use


Preface

I found a super nice thing today-selenium. Maybe I have too little knowledge and never used it. After playing a bit today, I found the New World and I can’t stop it! Hurry up and share such a good thing with everyone!

1. Introduction to Selenium

  Selenium is a tool for automated testing of web applications. Selenium tests run directly in the browser, just like a real user is operating. Supported browsers include IE (7, 8, 9, 10, 11), Mozilla Firefox, Safari, Google Chrome, Opera, etc.
  The main functions include: test compatibility with the browser-test your application to see if it can work well on different browsers and operating systems.
  Test system functions-create regression tests to verify software functions and user requirements. Support automatic recording actions and automatic generation of test scripts in different languages ​​such as .Net, Java, Perl, etc.
  Selenium is also an open source framework that is also released under the Apache License 2.0 protocol.

1. Support platform
  WebDriver supports browser testing on Android and BlackBerry mobile platforms. Android is currently the mobile platform with the largest market share. For automated testing on it, Appium is recommended. Appium extends the WebDriver protocol to support native applications, web applications, and hybrid applications on the ios platform and the Android platform.
2. Supported browsers
  WebDriver currently supports browsers including: Firefox, Chrome, IE, Edge, Opera, Safari. Why did you choose the above browsers for support? Mainly related to the browser's kernel.
3. Support modes
  HtmlUnit and PhantomJS are two special modes. We can regard them as pseudo-browsers. In this mode, they support the parsing of HTML, Java Saript, etc., but they will not actually render the page. Since CSS and GUI rendering are not performed, the operating efficiency is much faster than that of a real browser, and it is mainly used for functional testing.

Two, selenium installation

1. The premise is that there is a python environment and pip can be used normally
2. CMD opens the command line window and enters pip install selenium

At this time try to use

from selenium import webdriver

driver = webdriver.Chrome()    # Chrome浏览器

The following error will appear
Insert picture description here

Because when selenium was upgraded to 3.0, different browser drivers were standardized. If you want to use selenium to drive different browsers, you must download and set up different browser drivers separately.

3. Download the driver of the corresponding browser and configure environment variables

1. Download

Download link: https://npm.taobao.org/mirrors/chromedriver

Insert picture description here
Choose the version relative to your chorm browser version to download
Insert picture description here

I don’t know why there is no win64. Then I tried win32.

2. Configure environment variables

Create a new folder, eg: driver, and then put the downloaded driver into this folder

Insert picture description here

Then: My Computer -> Properties -> System Settings -> Advanced -> Environment Variables -> System Variables -> Path, add the "D:\application\Google chrome\driver" directory to the value of Path

Insert picture description here

( Reminder: Remember to click all the confirmations, otherwise it will be for nothing)

Then try the above program again and find that the browser is opened. So far, the selenium configuration is complete and you can start your performance~

Four, application

How to use it? I don’t know how, but I’m not going to learn it, so I found a learning content that is brief, clear, clear, and easy to use ( click me ~ ), readers can learn it, there is not much content, one You can finish watching and practice in two hours, very nice!

At last

I am very happy to share with everyone again, and the rest is...please praise! ! ! You have all seen this, creation is not easy, leave your precious likes~

For other selenium related content, please see: https://blog.csdn.net/weixin_45386875/article/details/113933541

Guess you like

Origin blog.csdn.net/weixin_45386875/article/details/113849069