python selenium 最简单示例
使用 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 最简单示例的更多相关文章
- python selenium 使用unittest 示例
python selenium 使用unittest 示例 并等待某个元素示例 from selenium.webdriver.support.ui import WebDriverWait from ...
- C#调用Python脚本的简单示例
C#调用Python脚本的简单示例 分类:Python (2311) (0) 举报 收藏 IronPython是一种在 .NET及 Mono上的 Python实现,由微软的 Jim Huguni ...
- Python+selenium之简单介绍unittest单元测试框架
Python+selenium之简单介绍unittest单元测试框架 一.unittest简单介绍 unittest支持测试自动化,共享测试用例中的初始化和关闭退出代码,在unittest中最小单元是 ...
- python+selenium之简单介绍继承
python+selenium之简单介绍继承 一.此例简单的介绍一下继承 1.面向对象的编程带来的主要好处之一是代码的重用,实现这种重用的方法之一是通过继承机制.继承完全可以理解成类之间的类型和子类型 ...
- 用map函数来完成Python并行任务的简单示例
众所周知,Python的并行处理能力很不理想.我认为如果不考虑线程和GIL的标准参数(它们大多是合法的),其原因不是因为技术不到位,而是我们的使用方法不恰当.大多数关于Python线程和多进程的教材虽 ...
- 【Python Selenium】简单数据生成脚本
最近因工作需要,写了一个简单的自动化脚本,纯属学习,顺便学习下selenium模块. 废话不多说,直接上代码!! 这里一位大神重写了元素定位.send_keys等方法,咱们直接进行调用. 适用Pyth ...
- python+selenium进行简单验证码获取
# _*_ coding:utf-8 _*_from PIL import Imagefrom selenium import webdriverimport pytesseractimport ti ...
- python信号signal简单示例
进程间通信之类的,用得着, 可以自定义接到信息之后的动作. file1.py #!/usr/bin/env python # -*- coding: utf-8 -*- import os impor ...
- Python + selenium + pycharm 环境部署细节 和selenium、Jenkins简单介绍
一.测试体系:Python + selenium + pycharm + Jenkins/docker 环境搭建: 1.安装python 3.4/3.5 2/3.6/ 3.7 2.配置环境变量 3.p ...
随机推荐
- <input>内容居中、去框、不可编辑等
<input class="i" type="text" value="Sin(x)" readonly="readonly ...
- EJS 语法
教程
- 练习 python之数据库增删改查
# 文件存储时可以这样表示 ## id,name,age,phone,dept,enroll_date# 1,Alex Li,22,13651054608,IT,2013-04-01# 2,Jack ...
- 什么是 CI/CD?
什么是 CI/CD? 在软件开发中经常会提到持续集成Continuous Integration(CI)和持续交付Continuous Delivery(CD)这几个术语.但它们真正的意思是什么呢? ...
- node+mysql,实现基本的增删改查,附带跟踪记录和运行时间记录
Node + mysql 实现基础的增删改查,以及性能测试. 网上有很多这样的例子,我也是找来学习的. 感觉node对mysql的操作非常简单,也很实用,比如自带防止sql注入的功能,一开始还担心注入 ...
- mysql 新建用户并赋予远程访问权限
不多说直接上代码 [root@demo /]# mysql -u root -p #登录服务器数据库 Enter password:123xxx #1.创建一个新用户 testuser 密码为 tes ...
- Γ(a) 的两种方差与均值
所以 这里是满足 Be(x+1,n-x+1),如果是要服从Be(a,b) 相应的后验概率
- C#如何使SQLite程序集既能适应32位系统也能适应64位系统
分享5: 需求:都知道Sqlite3是分32位和64位版本的,那如果将一个Sqlite3.dll文件全适用 分析:Sqlite是种轻量级的数据库文件,使用了混合编程而成的,一部分采用非托管的C++代码 ...
- stm32矩阵键盘扫描数据通过USB发送
Keyboard.c #include "keyboard.h"#include "my_usb.h"#include " ...
- styled-components解决全局样式'injectGlobal' 废除的问题
最新版的 styled-components v4 已经将原有的 injectGlobal() 方法替换成了 createGlobalStyle() ,而且用法也和之前的 injectGlobal 方 ...