使用 pip 安装  selenium

下载 chromedriver,添加在PATH中

# -*- coding: utf-8 -*-  

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
import time # Create a new instance of the browser driver
driver = webdriver.Chrome() ##可以替换为IE(), Firefox() Chrome() # go to the google home page
driver.get("https://www.google.com") # find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name("q") # type in the search
inputElement.send_keys("Cheese!") # submit the form. (although google automatically searches now without submitting)
inputElement.submit() # the page is ajaxy so the title is originally this:
print(driver.title) try:
# we have to wait for the page to refresh, the last thing that seems to be updated is the title
WebDriverWait(driver, 10).until(lambda driver : driver.title.lower().startswith("cheese!")) # You should see "cheese! - Google Search"
print(driver.title) finally:
driver.quit()

python selenium 最简单示例的更多相关文章

  1. python selenium 使用unittest 示例

    python selenium 使用unittest 示例 并等待某个元素示例 from selenium.webdriver.support.ui import WebDriverWait from ...

  2. C#调用Python脚本的简单示例

    C#调用Python脚本的简单示例 分类:Python (2311)  (0)  举报  收藏 IronPython是一种在 .NET及 Mono上的 Python实现,由微软的 Jim Huguni ...

  3. Python+selenium之简单介绍unittest单元测试框架

    Python+selenium之简单介绍unittest单元测试框架 一.unittest简单介绍 unittest支持测试自动化,共享测试用例中的初始化和关闭退出代码,在unittest中最小单元是 ...

  4. python+selenium之简单介绍继承

    python+selenium之简单介绍继承 一.此例简单的介绍一下继承 1.面向对象的编程带来的主要好处之一是代码的重用,实现这种重用的方法之一是通过继承机制.继承完全可以理解成类之间的类型和子类型 ...

  5. 用map函数来完成Python并行任务的简单示例

    众所周知,Python的并行处理能力很不理想.我认为如果不考虑线程和GIL的标准参数(它们大多是合法的),其原因不是因为技术不到位,而是我们的使用方法不恰当.大多数关于Python线程和多进程的教材虽 ...

  6. 【Python Selenium】简单数据生成脚本

    最近因工作需要,写了一个简单的自动化脚本,纯属学习,顺便学习下selenium模块. 废话不多说,直接上代码!! 这里一位大神重写了元素定位.send_keys等方法,咱们直接进行调用. 适用Pyth ...

  7. python+selenium进行简单验证码获取

    # _*_ coding:utf-8 _*_from PIL import Imagefrom selenium import webdriverimport pytesseractimport ti ...

  8. python信号signal简单示例

    进程间通信之类的,用得着, 可以自定义接到信息之后的动作. file1.py #!/usr/bin/env python # -*- coding: utf-8 -*- import os impor ...

  9. Python + selenium + pycharm 环境部署细节 和selenium、Jenkins简单介绍

    一.测试体系:Python + selenium + pycharm + Jenkins/docker 环境搭建: 1.安装python 3.4/3.5 2/3.6/ 3.7 2.配置环境变量 3.p ...

随机推荐

  1. WebStrom中实现Vue项目的快速启动

    工具:WebStrom+vue 前提:你已经安装了node.js,vuejs,会创建vue项目等一系列的操作 发生场景:希望在WebStrom中能够快速启动vue的项目,省去npm install,  ...

  2. kubernetes deployment升级和回滚

    a.创建deployment pod kubectl run mynginx --image=docker.io/nginx: --record 准备svc文件 apiVersion: v1 kind ...

  3. redux 简介

    概述 Redux 本身是个极其简单的状态管理框架, 它的简单体现在概念少, 流程明确. 但是, 正是因为简单, 使用上没有强制的约束, 所以如果用不好, 反而会让状态管理更加混乱. 我觉得, 用好 R ...

  4. 《神经网络算法与实现-基于Java语言》的读书笔记

    文章提纲 全书总评 读书笔记 C1.初识神经网络 C2.神经网络是如何学习的 C3.有监督学习(运用感知机) C4.无监督学习(自组织映射) Rreferences(参考文献) 全书总评 书本印刷质量 ...

  5. ERROR:"org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /config/topics/test" when creating or deleting Kafka operations authorized through the Ranger policies

    PROBLEM DESCRIPTION When creating or deleting topics in Kafka, they cannot be authorized through the ...

  6. 解决consul覆盖注册

    默认注册consul的服务id为服务名-端口号,相同的服务名和端口号注册会覆盖 解决方式: 1.自定义Consul注册Id import com.ecwid.consul.v1.ConsulClien ...

  7. QPen

    Help on class QPen in module PyQt5.QtGui: class QPen(sip.simplewrapper) |  QPen() |  QPen(Qt.PenStyl ...

  8. python操作Excel、openpyxl 之图表,折线图、饼图、柱状图等

    一.准备 需要模块: from openpyxl.workbook import Workbook from openpyxl.chart import Series,LineChart, Refer ...

  9. 前端之DOM操作

    一.概念 javascript javascript是一种脚本语言,可以被浏览器解析,所以它可以称之为前端的三把利器之一. javascript跟java没有半毛钱关系. 声明局部变量:使用关键字va ...

  10. SpringMVC model 多余字段 忽略

    spring-mybaits的model中如何通过注解忽略非数据库字段?——CSDN问答频道https://ask.csdn.net/questions/643534 ObjectMapper忽略多余 ...