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 ...
随机推荐
- (PASS)字符数组\字符串数组 和 字符串 的相互转换
1,字符数组 转换为 字符串 java可以使用两种方法直接将字符数组转为字符串. 方法1:直接在构造String时转换. char[] data = {'a', 'b', 'c'}; String s ...
- No parser no filepath given问题解决
关于 vue 项目 run dev 的时候,控制台警告: No parser and no filepath given, using 'babylon' the parser now but thi ...
- 转:深入浅出cache写策略
转自:http://www.ssdfans.com www.ssdfans.com › blog › 2018/07/27 › 深入浅出cach... 随着计算机行业的飞速发展,CPU的速度和内存的大 ...
- python模块:typing
很多人在写完代码一段时间后回过头看代码,很可能忘记了自己写的函数需要传什么参数,返回什么类型的结果,就不得不去阅读代码的具体内容,降低了阅读的速度,加上Python本身就是一门弱类型的语言,这种现象就 ...
- mongodb常用基本命令
一.数据库常用命令 1.help查看命令提示 help db.help() db.test.help() db.test.find().help() 2.创建.切换数据库 use movies 3.查 ...
- HTML——表单标签
表单标签(掌握) 现实中的表单,类似我们去银行办理信用卡填写的单子. 如下图: 目的是为了收集用户信息. 在我们网页中, 我们也需要跟用户进行交互,收集用户资料,此时也需要表单. 在HTML中,一个完 ...
- NX二次开发-UFUN移动工程图视图UF_DRAW_move_view
#include <uf.h> #include <uf_draw.h> #include <uf_drf.h> #include <uf_obj.h> ...
- 简单HOOK SSDT实现文件防删除
http://www.rosoo.net/a/201001/8347.html
- hexo next主题深度优化(四),自定义一个share功能,share.js。
文章目录 背景: 开始: 引入资源: 代码 关键的一步 附:方便学习的小demo 一次成功后还出现上面的bug 结束 2018.12.23发现bug(读者可忽略) 个人博客:https://mmmmm ...
- 20130318 word2013 mathtype
1.word2013 下如何安装mathtype 1.word2013已经装好 2.下载mathtype6.9 3. 公式编辑器Mathtype安装后无法加载到word的解决办法http://w5 ...