selenium python bindings 初步用法及简单参考例子
掌握selenium最简单的方法就是参考例子进行学习,下面给出之前项目的测试例子及分析
# -*- coding: utf-8 -*-
import time
from selenium import webdriver
# 使用firefox浏览器来展示效果,创建了selenium WebDriver的实例
driver = webdriver.Firefox()
#driver.get方法打开测试网址 127.0.0.1:8000/ChasingSomeone
driver.get('http://127.0.0.1:8000/ChasingSomeone/')
# 最大化屏幕(除展示用可忽略)
driver.maximize_window()
sleep 单位以秒计算,方法中不用加单位
time.sleep(1)
# 找到页面元素并且输入用户名和密码,具体find_element_by_*方法会在定位元素中具体总结
# send_keys 函数向相应页面元素传值
signIn_email = driver.find_element_by_name('username')
signIn_email.send_keys("cher@gmail.com")
signIn_password = driver.find_element_by_name('password')
signIn_password.send_keys("123")
time.sleep(2)
# 找到登陆buttom,并点击提交
signIn_submit_button = driver.find_element_by_name('login')
signIn_submit_button.click()
time.sleep(2) # 退出 driver.close()
这就是一个最简单的python selenium例子,之后添加的功能都会基于这样的简单例子扩充
再给出一个官网例子,可以自己分析,分析完可以上官网确认,附链接
from selenium import webdriver
from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
内容参考 http://selenium-python.readthedocs.io/installation.html
selenium python bindings 初步用法及简单参考例子的更多相关文章
- <译>Selenium Python Bindings 1 - Installation
Installation Introduction Selenium Python bindings 提供了一个简单的API来使用Selenium WebDriver编写使用功能/验收测试.通过Sel ...
- selenium python bindings 元素定位
1. 辅助 Firepath Firefox是所有做前端的必不可少的浏览器因为firebug的页面元素显示很清晰.用selenium 去定位元素的时候Firefox还有一个非常友好的工具就是firep ...
- <译>Selenium Python Bindings 2 - Getting Started
Simple Usage如果你已经安装了Selenium Python,你可以通过Python这样使用: #coding=gbk ''' Created on 2014年5月6日 @author: u ...
- <译>Selenium Python Bindings 5 - Waits
如今,大多数的Web应用程序使用AJAX技术.当页面加载到浏览器,页面中的元素也许在不同的时间间隔内加载.这使得元素很难定位,如果在DOM中的元素没有呈现,它将抛出ElementNotVisibleE ...
- 扩展Python模块系列(二)----一个简单的例子
本节使用一个简单的例子引出Python C/C++ API的详细使用方法.针对的是CPython的解释器. 目标:创建一个Python内建模块test,提供一个功能函数distance, 计算空间中两 ...
- selenium python bindings 写测试用例
这章总结selenium在UI测试方面的用法 import unittest from selenium import webdriver from selenium.webdriver.common ...
- <译>Selenium Python Bindings 6 - WebDriver API
本章涉及Selenium WebDriver的所有接口. Recommended Import Style 推荐的导入风格如下: from selenium import webdriver 然后,你 ...
- <译>Selenium Python Bindings 4 - Locating Eelements
有各种不同的策略来定位页面中的元素.你可以使用最合适定位方式用于你的用例.Selenium提供了以下方法来定位页面中的元素: find_element_by_id find_element_by_na ...
- <译>Selenium Python Bindings 3 - Navigating
当你想要通过webdriver导航到一个链接,正常的方式点是通过调用get方法: driver.get("http://www.google.com") Interacting w ...
随机推荐
- cpu相关信息查看
查看CPU型号:grep "model name" /proc/cpuinfo | uniqdmidecode -s processor-version | uniq 查看物理CP ...
- 强大的httpClientUtils
<!-- https://mvnrepository.com/artifact/com.arronlong/httpclientutil --> <dependency> &l ...
- AnalyticDB for PostgreSQL 6.0 新特性介绍
阿里云 AnalyticDB for PostgreSQL 为采用MPP架构的分布式集群数据库,完备支持SQL 2003,部分兼容Oracle语法,支持PL/SQL存储过程,触发器,支持标准数据库事务 ...
- BZOJ 3779: 重组病毒(线段树+lct+树剖)
题面 escription 黑客们通过对已有的病毒反编译,将许多不同的病毒重组,并重新编译出了新型的重组病毒.这种病毒的繁殖和变异能力极强.为了阻止这种病毒传播,某安全机构策划了一次实验,来研究这种病 ...
- NX二次开发-UFUN获取一个图层类别的tag UF_LAYER_ask_category_tag
NX11+VS2013 #include <uf.h> #include <uf_ui.h> #include <uf_layer.h> UF_initialize ...
- 最详尽使用指南:超快上手Jupyter Notebook
最详尽使用指南:超快上手Jupyter Notebook - CSDN博客https://blog.csdn.net/DataCastle/article/details/78890469
- CodeForces 1152E Neko and Flashback
题目链接:http://codeforces.com/problemset/problem/1152/E 题目大意 有一个 1~n-1 的排列p 和长度为 n 的数组 a,数组b,c定义如下: b:b ...
- 20140421 常量指针与指针常量; const指针; reinterpret_cast ;const_cast作用
1.reinterpret_cast<type_id>(表达式)的作用: type-id 必须是一个指针.引用.算术类型.函数指针或者成员指针.它可以把一个指针转换成一个整数,也可以把一个 ...
- 《DSP using MATLAB》Problem 8.46
下雨了,大风降温,一地树叶,终于进入冬季了 代码: %% ----------------------------------------------------------------------- ...
- csv转字典
with open('filename','r') as csv_f: reader = csv.reader(csv_f) fieldnames = next(reader) csv_reader ...