程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Teach you how to build a python+selenium automation environment (picture and text)

編輯:Python

Catalog

First step : install python Interpreter

The second step : install pycharm compiler .

  The third step : install selenium library

Step four : Download the browser driver

Step five : open pycharm Write the first automation demo Verify if there is a problem with the environment

Fast + Simply build the environment . If there are questions , Welcome to join the group to discuss and leave a message .

First step : install python Interpreter

Official website address :https://www.python.org/

Automated testing is best downloaded 3.7 Of .

After downloading, open this file , And then install it like a fool .

After installed ,win+r Open the command line window , Input python. If the following figure is displayed , It means the installation is successful . 

The second step : install pycharm compiler .

Just install it like a fool .

http://www.jetbrains.com/pycharm/download/#section=windows.

  The third step : install selenium library pip install selenium

Step four : Download the browser driver

I usually use chrome It's more representative .

Chrome:
https://sites.google.com/a/chromium.org/chromedriver/downloads( Need to climb over the wall )

Firefox:
https://github.com/mozilla/geckodriver/releases.

After the download , Place the drive in the python The folder scripts In the root directory .

Step five : open pycharm Write the first automation demo Verify if there is a problem with the environment

first demo

from selenium import webdriverimport timeimport unittestclass LoginPage(object): driver=webdriver.Firefox() driver.get("https://passport.hupu.com/pc/login?project=nba&from=pc") time.sleep(5) def test_login(self): self.driver.find_element_by_xpath("//*[@id='J_username']").click() self.driver.find_element_by_xpath("//*[@id='J_username']").clear() self.driver.find_element_by_xpath("//*[@id='J_username']").send_keys("18777777777") self.driver.find_element_by_xpath("//*[@id='J_pwd']").click() self.driver.find_element_by_xpath("//*[@id='J_pwd']").clear() self.driver.find_element_by_xpath("//*[@id='J_pwd']").send_keys("111111111") self.driver.find_element_by_xpath("//*[@id='SM_BTN_1']/div[1]/div[4]").click() time.sleep(6) def test_threads(self): self.driver.get("https://bbs.hupu.com/hcbig") time.sleep(6) self.driver.find_element_by_id("g_n").click() time.sleep(6) self.driver.find_element_by_id("atc_title").click() self.driver.find_element_by_id("atc_title").clear() self.driver.find_element_by_id("atc_title").send_keys(" Text post from orange ") self.driver.find_element_by_xpath("//body").click() self.driver.find_element_by_xpath("//body").send_keys(" Oranges use automated tests to send text messages ") self.driver.find_element_by_id("submitview").click()login=LoginPage()login.login()time.sleep(4)login.fatie_4524()

As long as you can start the browser successfully , And you can see that the mouse operates automatically , It means there is no problem with the environment . 

This is about hand-in-hand building python+selenium Automation environment ( Image & Text ) This is the end of the article , More about python selenium For the content of automatic environment construction, please search the previous articles of SDN or continue to browse the following related articles. I hope you will support SDN more in the future !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved