Selenium 安装和测试
2017-08-21 11:00
204 查看
>>>pip install -Uselenium
对于Chrome,
1)
下载Chrome drive:(是个独立的exe)
https://sites.google.com/a/chromium.org/chromedriver/home
参考文档做设置:
https://sites.google.com/a/chromium.org/chromedriver/getting-started
测试代码:
fromselenium import webdriver
fromselenium.common.exceptions import NoSuchElementException
fromselenium.webdriver.common.keys import Keys
importtime
browser =webdriver.Chrome('C:/Program Files (x86)/chromedriver.exe') # Optional argument, if not specified willsearch path.
browser.get("http://www.yahoo.com")# Load page
assert"Yahoo!" in browser.title
elem =browser.find_element_by_name("p1") # Find the query box
elem.send_keys("seleniumhq"+ Keys.RETURN)
time.sleep(0.2)# Let the page load, will be added to the API
try:
browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
exceptNoSuchElementException:
assert 0, "can't find seleniumhq"
browser.close()
对于Chrome,
1)
下载Chrome drive:(是个独立的exe)
https://sites.google.com/a/chromium.org/chromedriver/home
参考文档做设置:
https://sites.google.com/a/chromium.org/chromedriver/getting-started
测试代码:
fromselenium import webdriver
fromselenium.common.exceptions import NoSuchElementException
fromselenium.webdriver.common.keys import Keys
importtime
browser =webdriver.Chrome('C:/Program Files (x86)/chromedriver.exe') # Optional argument, if not specified willsearch path.
browser.get("http://www.yahoo.com")# Load page
assert"Yahoo!" in browser.title
elem =browser.find_element_by_name("p1") # Find the query box
elem.send_keys("seleniumhq"+ Keys.RETURN)
time.sleep(0.2)# Let the page load, will be added to the API
try:
browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
exceptNoSuchElementException:
assert 0, "can't find seleniumhq"
browser.close()
相关文章推荐
- Discuz建站教程:本地安装discuz网站,使用selenium做自动化测试
- [Selenium] 测试机器上安装了多个Firefox,如何指定运行哪一个?
- 需求:在openstack中安装极小的Linux,可以安装Firefox浏览器,接着安装selenium完成自动化网页测试
- selenium(一)简介,安装,配置,测试。
- 基于Python selenium2的测试环境的搭建与安装
- Selenium (1) —— Selenium安装与测试(101 Tutorial)
- web的自动化测试插件Selenium-IDE插件的安装使用
- python selenium 自动化测试环境安装
- [网页自动化/测试]Firefox selenium plugin 安装及使用
- selenium 2.44安装测试教程(附全程免费资料软件包下载)
- win7下安装chromedriver和selenium测试
- Selenium IDE-自动化ui测试插件安装及使用
- Web前台测试Selenium的安装与使用
- SIP网关压力测试工具SIPp的安装及使用详解
- Juniper IDP 测试license 申请,数据库安装,调用;日志服务器调用IDP日志
- vs2013的安装与使用 测试
- android 监听SDCard安装和卸载的代码片段(测试通过)
- MongoDB 安装及C#开发测试