菜鸟的Python之路

Python+selenium环境搭建

2017-03-01  本文已影响108人  Tester_Jingel

python+selenium.png

一、下载安装Python

下载并安装Python,此处博主使用的是Python3.5
点击下载Python3.5安装包(Windows64位)

二、配置环境变量

  • python安装完成后,打开cmd输入“Python”,若输出版本号已代表安装成功


    Python版本.png

三、安装pip和setuptool工具

四、安装selenium模块

打开cmd,进入到Python的scripts目录下,输入pip install -U selenium


安装selenium.png

五、开始你的第一个simple demo

打开Python IDE,ctrl+n新建文档,输入以下代码:

# -*-coding:utf-8-*-
#executable_path="F:\chengyuanyuanproject\python35\geckodriver.exe"
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.baidu.com")

browser.find_element_by_id("kw").send_keys("selenim")
browser.find_element_by_id("su").click()

browser.quit()
print ("百度测试成功O(∩_∩)O哈哈~")

常见问题:

  • 导入模块失败,打不开浏览器报错需要将这个下载到Python路径下
    selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
    geckodriver驱动下载地址

推荐Python学习链接:

今天有学习了一点,一天一步慢慢进步,哈哈向着目标前进,↖(ω)↗

上一篇 下一篇

猜你喜欢

热点阅读