selenium运行环境
selenium环境需要和浏览器兼容,最好去下载和浏览器一样版本的安装包
我们以Edge和Chrome浏览器为例子吧
Chrome在外面测试中占据了半壁江山,所以在Chrome上测试是有必要的。
Chrome浏览器环境下载
高版本下载地址
https://googlechromelabs.github.io/chrome-for-testing/#stable
低版本下载地址
https://registry.npmmirror.com/binary.html?path=chromedriver/
查看Chrome版本(Edge版本查看一样不再展示了,有问题可以找我)
1,进入Chrome浏览器
2.点击右上角的...
3.点击设置,进入关于Chrome就可以查看版本啦
下载完成对应安装包以后环境配置
进入下载完成安装包内选择.exe文件拷贝一下(ctrl+c)
打开python所在位置加入python文件夹内
上面.exe是Chrome的,下面.exe是Edge的
代码运行
环境配置好了开始第一个运行程序吧
from selenium import webdriver
import time
from time import sleep
from selenium.webdriver.common.by import By
# 包
driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
driver.find_element('id','kw').send_keys("pink@zhu")
driver.find_element("id","su").click()
sleep(2)
好的~这就是selenium的下载,环境配置和使用了