安装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. linux log4cplus安装和实例

    tar –xvf  log4cplus-1.1.3-rc5.tar.gz cd log4cplus-1.1.3-rc5 configure --prefix=/usr/local/log4cplus ...

  2. XAML 特效

    <Window x:Class="WpfApp5.MainWindow" xmlns="http://schemas.microsoft.com/winfx/200 ...

  3. 13-2 jquery介绍

    1 什么是 jQuery jQuery 是 js 的一个库,封装了我们开发过程中常用的一些功能,方便我们调用,提高开发效率. js库是把我们常用的功能放到一个单独的文件中,我们用的时候,直接引用到页面 ...

  4. The Top 50 Proprietary Programs that Drive You Crazy — and Their Open Source Alternatives

    The Top 50 Proprietary Programs that Drive You Crazy — and Their Open Source Alternatives 01 / 22 / ...

  5. Mybatis/Ibatis,数据库操作的返回值

    该问题,我百度了下,根本没发现什么有价值的文章:还是看源代码(详见最后附录)中的注释,最有效了!insert,返回值是:新插入行的主键(primary key):需要包含<selectKey&g ...

  6. 详解TableStore模糊查询——以订单场景为例

    背景 订单系统在各行各业中广泛应用,为消费者.商家后台.促销系统等第三方提供用户.产品.订单等多维度的管理和查询服务.为了挖掘出海量订单数据的潜能,丰富高效的查询必不可少.然而很多时候并不能给出完整准 ...

  7. 解决ubuntu的Idea启动No JDK found. Please validate either IDEA_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation.

    直接在idea安装目录下运行idea.sh可以正常启动,但是使用ubuntu的dash搜索出来的idea报错,No JDK found. Please validate either IDEA_JDK ...

  8. GPUtil是一个Python模块,使用nvidia-smi从NVIDA GPU获取GPU状态

    GPUtil是一个Python模块,使用nvidia-smi从NVIDA GPU获取GPU状态 一个Python模块,用于在Python中使用nvidia-smi以编程方式从NVIDA GPU获取GP ...

  9. Intellij Idea更换主题

    <h1 class="title">Intellij Idea更换主题</h1> <!-- 作者区域 --> <div class=&qu ...

  10. vue v-for循环使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...