OscarXie.net

关注质量与体验——电子商务与自动化测试

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  436 随笔 :: 0 文章 :: 221 评论 :: 69万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

有一段时间没有关注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")
10     
11     # find the element that's name attribute is q (the google search box)
12     inputElement = driver.find_element_by_name("q")
13     
14     # type in the search
15     inputElement.send_keys("Cheese!")
16     
17     # submit the form (although google automatically searches now without submitting)
18     inputElement.submit()
19     
20     # the page is ajaxy so the title is originally this:
21     print driver.title
22     
23     # we have to wait for the page to refresh, the last thing that seems to be updated is the title
24     while not driver.title.startswith("cheese!"):
25         # this is an infinite loop... should probably put some logic to break after x time
26         # sleep for a second
27         time.sleep(1)
28     
29     # You should see "cheese! - Google Search"
30     print driver.title
31     

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 

posted on   oscarxie  阅读(2672)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
历史上的今天:
2010-07-11 口碑式销售的体验
点击右上角即可分享
微信分享提示