安装python

  • 官网直接下载当前最新版的python

  • 百度搜索Python3.6安装步骤
    • Python安装步骤:自行百度,暂不提供

安装selenium

  • 安装好Python3之后,默认就会有pip,使用pip进行安装:
pip install selenium

安装Firefox geckodriver

  • 下载最新版geckodriver

  • 解压下载的驱动(该软件无需安装,解压缩即可)
    • 比如解压缩到路径: D:/browser_drivers/
  • 添加geckodriver环境变量
    • 将解压缩后的geckodriver路径添加的Windows环境变量中
  • 添加Firefox环境变量
    • 添加Firefox的可执行程序路径到环境变量中

WebDriver下载地址备用

Chromedriver下载地址

Chromedriver备用地址

IEdriver下载地址

IEdriver备用地址

firefox下载地址

所有下载地址

Selenium简要教程

  • 环境搭建验证
# 打开CMD窗口,输入以下验证浏览器是否正常打开
python from selenium import webdriver driver=webdriver.Firefox() driver.get("https://www.baidu.com")
  • 贴出一段简要的代码,仅供参考,这段代码做了以下几件事:

    • 打开Firefox浏览器
    • 打开baidu页面
    • 输入搜索内容
    • 点击搜索
# -*- coding: utf- -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re class Test8(unittest.TestCase):
def setUp(self):
#打开火狐浏览器
self.driver = webdriver.Firefox()
#设置超时时间为30s
self.driver.implicitly_wait()
#设置URL
self.base_url = "https://www.baidu.com/"
self.verificationErrors = []
self.accept_next_alert = True def test_8(self):
driver = self.driver
#打开URL
driver.get(self.base_url + "/")
#延时
time.sleep()
#清空文本框
driver.find_element_by_id("kw").clear()
#输入搜索内容
driver.find_element_by_id("kw").send_keys("")
time.sleep()
#点击搜索
driver.find_element_by_id("su").click()
time.sleep() def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: return False
return True def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors) if __name__ == "__main__":
unittest.main()

Selenium3+Python3环境搭建的更多相关文章

  1. 1.6 selenium3+firefox环境搭建

    1.6 selenium3+firefox环境搭建 有不少小伙伴在安装selenium环境后启动firefox报错,因为现在selenium升级到3.0了,跟2.0的版本还有有一点区别的.(备注:这里 ...

  2. Python3环境搭建

    Python3环境搭建   Windows系统下安装Python3 Python3 下载 Python3 最新源码,二进制文档,新闻资讯等可以在 Python 的官网查看到: Python 官网:ht ...

  3. 【Python学习】Python3 环境搭建

    参考地址:http://www.runoob.com/python3/python3-install.html Python3 环境搭建 本章节我们将向大家介绍如何在本地搭建 Python3 开发环境 ...

  4. 1. Python3 环境搭建

    Python3 环境搭建 开门见山,其他关于Python发展史.语言类型.优缺点等等 可以自己去百度百度,这里就不多说了.其实基本想要学这门语言的时候,你已经了解差不多了!!! Python的运行环境 ...

  5. Linux下安装python3环境搭建

    Linux下python3环境搭建 Linux安装软件有哪些方式? rpm软件包 手动安装 拒绝此方式 需要手动解决依赖关系 yum自动化安装 自动处理依赖关系 非常好用 源代码编译安装,可自定义的功 ...

  6. Centos7 python3环境搭建 兼容python2.7

    Centos7 python3环境搭建 兼容python2.7 安装前提依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel ...

  7. python3+ selenium3开发环境搭建-手把手教你安装python(详细)

    环境搭建 基于python3和selenium3做自动化测试,俗话说:工欲善其事必先利其器:没有金刚钻就不揽那瓷器活,磨刀不误砍柴工,因此你必须会搭建基本的开发环境,掌握python基本的语法和一个I ...

  8. python3+ selenium3开发环境搭建

    环境搭建 基于python3和selenium3做自动化测试,俗话说:工欲善其事必先利其器:没有金刚钻就不揽那瓷器活,磨刀不误砍柴工,因此你必须会搭建基本的开发环境,掌握python基本的语法和一个I ...

  9. python3环境搭建(uWSGI+django+nginx+python+MySQL)

    1.系统环境,必要知识 #cat /etc/redhat-release CentOS Linux release (Core) #uname -r -.el7.x86_64 暂时关闭防护墙,关闭se ...

随机推荐

  1. VS开发ArcEngine时的一个异常信息——“ArcGIS version not specified. You must call RuntimeManager.Bind before creating any ArcGIS components.”

    问题描述:程序报错“ArcGIS version not specified. You must call RuntimeManager.Bind before creating any ArcGIS ...

  2. iOS-CoreLocation:无论你在哪里,我都要找到你!

    作者:@翁呀伟呀 授权本站转载 CoreLocation 1.定位 使用步骤: 创建CLLocationManager示例,并且需要强引用它 设置CLLocationManager的代理,监听并获取所 ...

  3. HZOJ 随

    这个题的题解并不想写……一个写的很详细的blog 第1个测试点:mod=2,a[i]<mod(仔细看题),则n个数字都是1,直接输出1即可. 第2个测试点:每次乘上去的数字只有一种选择,快速幂即 ...

  4. mysql查同个实例两个数据库中的表名差异

    select TABLE_NAME from ( select TABLE_NAME ,) as cnt from information_schema.tables where TABLE_SCHE ...

  5. H3C 命令级别

  6. 2019年CPS-J复赛题解

    题目涉及算法: 数字游戏:字符串入门题: 公交换乘:模拟: 纪念品:完全背包: 数字游戏:广搜/最短路. 数字游戏 题目链接:https://www.luogu.com.cn/problem/P566 ...

  7. js获取当前时间戳以及前一天时间戳

    js获取当前时间戳以及前一天时间戳(毫秒) var timestamp = (new Date()).getTime(); console.log(timestamp);//打印当前时间戳 conso ...

  8. Project Euler Problem 8-Largest product in a series

    直接暴力 写完才想到,代码写矬了,扫一遍就出结果了,哪还用我写的这么麻烦 ss = '''73167176531330624919225119674426574742355349194934 9698 ...

  9. jieba中文分词源码分析(四)

    一.未登录词问题在jieba中文分词的第一节曾提到未登录词问题 中文分词的难点 分词规范,词的定义还不明确 (<统计自然语言处理>宗成庆)歧义切分问题,交集型切分问题,多义组合型切分歧义等 ...

  10. 使用属性position:fixed的时候如何才能让div居中

    css: .aa{ position: fixed; top: 200px; left: 0px; right: 0px; width: 200px; height: 200px; margin-le ...