Selenium & WebDriver
2011-07-11 12:13
344 查看
有一段时间没有关注Selenium了,最近浏览了下,Selenium已经出到2.0rc3了,最大的变化是WebDriver集成了进来
什么是WebDriver请看这篇wiki,介绍得很详细,http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
所以Selenium2.0其实就是Selenium 1.x+WebDriver。
WebDriver除了支持PC浏览器之外,最大的亮点是能够支持移动浏览器——WebDriverForMobileBrowsers /
AndroidDriver ,支持Android and iOS
当然多种开发语言的优点还是保持着,看了下 WebDriver的例子,代码比过去的Selenium更简练,
1 from selenium import webdriver
2 import time
3
4 if __name__=='__main__':
5 # Create a new instance of the Firefox driver
6 driver = webdriver.Firefox()
7
8 # go to the google home page
9 driver.get("http://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
# we have to wait for the page to refresh, the last thing that seems to be updated is the title
while not driver.title.startswith("cheese!"):
# this is an infinite loop... should probably put some logic to break after x time
# sleep for a second
time.sleep(1)
# You should see "cheese! - Google Search"
print driver.title
32 driver.quit()
Selenium的启动,除了默认的方式
java -jar selenium-server.jar
对于公司内部的代理还可以使用
java -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts=www.google.cn -jar selenium-server.jar
java -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts=www.google.cn -jar selenium-server.jar -avoidProxy
不过我比较喜欢新建一个firefox profile,用firefox.exe -ProfileManager创建
java -jar selenium-server.jar -firefoxProfileTemplate "/home/oscarxie/.mozilla/firefox/binmn2bo.selenium" -multiWindow
java -jar selenium-server.jar -firefoxProfileTemplate "/home/oscarxie/.mozilla/firefox/binmn2bo.selenium"
PS:
开源应用架构之Selenium WebDriver(上)
http://seleniumhq.org/projects/
http://code.google.com/p/selenium/
http://seleniumhq.org/docs/
http://code.google.com/p/selenium/w/list
http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html
什么是WebDriver请看这篇wiki,介绍得很详细,http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
所以Selenium2.0其实就是Selenium 1.x+WebDriver。
WebDriver除了支持PC浏览器之外,最大的亮点是能够支持移动浏览器——WebDriverForMobileBrowsers /
AndroidDriver ,支持Android and iOS
当然多种开发语言的优点还是保持着,看了下 WebDriver的例子,代码比过去的Selenium更简练,
1 from selenium import webdriver
2 import time
3
4 if __name__=='__main__':
5 # Create a new instance of the Firefox driver
6 driver = webdriver.Firefox()
7
8 # go to the google home page
9 driver.get("http://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
# we have to wait for the page to refresh, the last thing that seems to be updated is the title
while not driver.title.startswith("cheese!"):
# this is an infinite loop... should probably put some logic to break after x time
# sleep for a second
time.sleep(1)
# You should see "cheese! - Google Search"
print driver.title
32 driver.quit()
Selenium的启动,除了默认的方式
java -jar selenium-server.jar
对于公司内部的代理还可以使用
java -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts=www.google.cn -jar selenium-server.jar
java -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts=www.google.cn -jar selenium-server.jar -avoidProxy
不过我比较喜欢新建一个firefox profile,用firefox.exe -ProfileManager创建
java -jar selenium-server.jar -firefoxProfileTemplate "/home/oscarxie/.mozilla/firefox/binmn2bo.selenium" -multiWindow
java -jar selenium-server.jar -firefoxProfileTemplate "/home/oscarxie/.mozilla/firefox/binmn2bo.selenium"
PS:
开源应用架构之Selenium WebDriver(上)
http://seleniumhq.org/projects/
http://code.google.com/p/selenium/
http://seleniumhq.org/docs/
http://code.google.com/p/selenium/w/list
http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html
相关文章推荐
- selenium2.0&WebDriver学习系列(一些需要注意的知识点)
- Selenium Webdriver 学习总结-Selenium Grid & Webdriver(九)
- jenkins里跑selenium webdriver,Chrome浏览器不能打开&&unknown error: unable to discover open pages
- Selenium2(WebDriver):启动浏览器、设置profile&加载插件
- Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&加载插件
- selenium webdriver获取不到标签文本及将html特殊符号&转换为正常字符的方法
- Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&加载插件
- EventFiringWebDriver & Event Listeners in Selenium
- Selenium Webdriver 学习总结-Selenium Grid & Webdriver(九)
- selenium.common.exceptions.WebDriverException: Message: "Can't load the profile.
- Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&加载插件
- 构建Python+Selenium2(2=WebDriver)自动化测试环境<二>:IE、Chrome和Firefox运行
- Selenium2(基于JAVA的WebDriver)---启动浏览器、设置profile&加载插件
- 【转】Watir, Selenium & WebDriver
- Selenium & Webdriver 远程测试和多线程并发测试
- Selenium & Nunit GUI & WebDriver
- Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&加载插件
- Selenium 2 & WebDriver &多线程 并发
- WebDriver拾级而上·之十一 在selenium2.0中使用selenium1.0的API
- UI自动化测试篇 :Selenium2(Webdriver)&TestNG自动化测试环境搭建