selenium在Windows中第一次使用

需要安装,python3.pip ,

1.首先安装好selenium  pip install selenium

2.把python路径加到path中(此步骤不确定是否需要,应该我在执行时遇到了报错path路径)

3.下载chromedriver软件 (注意:需要下载当前使用chrome对应的版本,在notes.txt中记录对应的版本)     https://npm.taobao.org/mirrors/chromedriver/(下载网址)

源码

#引用

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#chromedriver = 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37'

#打开浏览器
driver = webdriver.Chrome()
#get请求
driver.get('http://www.python.org')

assert 'Python' in driver.title
elem =driver.find_element_by_name('q')
elem.clear()
elem.send_keys('pycon')
elem.send_keys(Keys.RETURN)
assert 'No results found.' not in driver.page_source
#等待5秒
time.sleep(5)
#关闭chrome
driver.close()

猜你喜欢

转载自blog.csdn.net/lixj_qi/article/details/82112361