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

Python automated testing selenium (I)

編輯:Python

One 、 Introduce
Selenium Is an automated testing tool for testing websites , Support for a variety of browsers including Chrome、Firefox、Safari And so on the mainstream interface browser , It also supports phantomJS Interface free browser
official API file :http://seleniumhq.github.io/selenium/docs/api/py/api.html

Two 、 Environmental installation
1、 Installation Library
2、 download chromedriver : Sign in http://chromedriver.storage.googleapis.com/index.html download ( Please check the version corresponding to the browser Online )
View corresponding version , Take Google browser for example
Open the browser , Press F12, Click on console
navigator.appCodeName
navigator.appVersion
navigator.userAgent
Press F12, Click on console, Enter the following command , Can be seen as 102.0.5005.115 edition

After downloading chromedriver.exe File to python.exe In the directory Such as : D:\Program Files\Python
thus , Environment installation complete

3、 ... and 、 Write code
Search box positioning

Baidu search button positioning

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time
import os
from selenium import webdriver
# Instantiate the browser 
driver = webdriver.Chrome()
# Open the url 
driver.get('https://www.baidu.com/')
# demand 
driver.find_element(By.ID,"kw").send_keys(' Pot pot ')
driver.find_element(By.ID, "su").click()# Click button 
sleep(2)
# Close page 
driver.quit()

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