python学习(一)Use Python to Drive Selenium RC
2012-02-24 14:31
281 查看
Selenium RC支持多种编程语言驱动客户端浏览器,这里主要介绍使用Python在Windows下驱动Selenium RC。Python是一种面向对象的解释性的计算机程序设计语言。
1. 准备工作
安装jdk。jdk-6u10-rc2-bin-b32-windows-i586-p-12_sep_2008.exe
安装python。python-2.7.2.msi
下载selenium RC。selenium-remote-control-1.0.3
2.启动selenium server。解压selenium RC ,在selenium-server.jar目录下通过运行命令java -jar selenium-server.jar -interactive启动服务。
可以通过写批处理脚本,启动。如下:
@echo off
title Selenium Server
D:
cd D:\selenium\selenium-remote-control-1.0.3\selenium-server-1.0.3
java -jar selenium-server.jar -interactive
3.在IE上搜索hello world为例:
View Code
这里,仅使用*iexplore则表示浏览器安装在默认的路径,即IE安装在"C:\Program Files\Internet Explorer\iexplore.exe",如果不是安装在默认的路径,需要指明浏览器安装的地址,如:"*firefox D:\Program Files\Mozilla Firefox\\firefox.exe"。
"def tearDown(self):
self.selenium.stop()"
这段表示浏览器运行结束后直接关闭浏览器,这里可以注释掉。
在python上点击F5开始运行python代码。通过selenium直接调用IE浏览器进行客户端运行。
同时命令行窗口显示Selenium Server进行的每个步骤操作。
note:使用firefox浏览器时需注意,目前Selenium RC不支持firefox3.0版本,不管是使用"*chrome"还是"*firefox",都无法把Firefox调出;但是如果机器上使用的Firefox是低于3.0版本,那么可以直接使用"*chrome"这个参数。
在运行之前,需要将Firefox中的代理设置成和Selenium Server一致,Localhost,端口为4444。
1. 准备工作
安装jdk。jdk-6u10-rc2-bin-b32-windows-i586-p-12_sep_2008.exe
安装python。python-2.7.2.msi
下载selenium RC。selenium-remote-control-1.0.3
2.启动selenium server。解压selenium RC ,在selenium-server.jar目录下通过运行命令java -jar selenium-server.jar -interactive启动服务。
可以通过写批处理脚本,启动。如下:
@echo off
title Selenium Server
D:
cd D:\selenium\selenium-remote-control-1.0.3\selenium-server-1.0.3
java -jar selenium-server.jar -interactive
3.在IE上搜索hello world为例:
View Code
from selenium import selenium import unittest class Untitled(unittest.TestCase): def setUp(self): self.verificationErrors = [] self.selenium = selenium("localhost", 4444, "*iexplore", "http://www.google.com/webhp") self.selenium.start() def test_untitled(self): sel = self.selenium sel.open("http://www.google.com.hk/") sel.type("q", "hello world") sel.click("name=btnG") sel.wait_for_page_to_load(8000) self.assertEqual("hello world - Google 搜索",sel.get_title()) #def tearDown(self): #self.selenium.stop() #self.assertEqual([], self.verificationErrors) if __name__ == "__main__": unittest.main()
这里,仅使用*iexplore则表示浏览器安装在默认的路径,即IE安装在"C:\Program Files\Internet Explorer\iexplore.exe",如果不是安装在默认的路径,需要指明浏览器安装的地址,如:"*firefox D:\Program Files\Mozilla Firefox\\firefox.exe"。
"def tearDown(self):
self.selenium.stop()"
这段表示浏览器运行结束后直接关闭浏览器,这里可以注释掉。
在python上点击F5开始运行python代码。通过selenium直接调用IE浏览器进行客户端运行。
同时命令行窗口显示Selenium Server进行的每个步骤操作。
note:使用firefox浏览器时需注意,目前Selenium RC不支持firefox3.0版本,不管是使用"*chrome"还是"*firefox",都无法把Firefox调出;但是如果机器上使用的Firefox是低于3.0版本,那么可以直接使用"*chrome"这个参数。
在运行之前,需要将Firefox中的代理设置成和Selenium Server一致,Localhost,端口为4444。
相关文章推荐
- Use Python to Drive Selenium RC
- Use Python to Drive Selenium RC
- Use Python to Drive Selenium RC(转)
- Use Python to Drive Selenium RC(转)
- Python use Selenium to control the webdriver
- Selenium2 Python 自动化测试实战学习笔记(四)
- 学习selenium python版最初的一个小想法
- how to use pandas in python
- HOW TO: Install Chromedriver for Mac OS X / Selenium / Python
- HOWTO Use Python in the web — Python v3.0.1 documentation
- Python爬虫(入门+进阶)学习笔记 1-8 使用自动化神器Selenium爬取动态网页(案例三:爬取淘宝商品)
- Selenium2 Python 自动化测试实战学习笔记(六)
- 20170921学习笔记Selenium 2 第三章Python基础
- Use python to make a table frame template instance
- Selenium2 Python 自动化测试实战学习笔记(八)
- python学习--windows下安装Numpy包的错误:Unable to find vcvarsall.bat
- python3.5+django1.10:selenium.common.exceptions.WebDriverException->moveto did not match a known com
- selenium-webdriver (python)(一)学习笔记
- How can I force Python's file.write() to use the same newline format in Windows as in Linux (“\r\n”
- Selenium RC For Python:教程2