selenium使用中遇到的问题

1、 Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: XP

Build info: version: '2.16.1', revision: '15405', time: '2012-01-05 12:30:12'
解决办法:

我们只要在WebDriver driver = new FirefoxDriver(); 前面指定我们浏览器的具体信息即可:

System.setProperty ( "webdriver.firefox.bin" , "E:/Program Files/Mozilla Firefox/firefox.exe" );

WebDriver driver = new FirefoxDriver();

 

2、Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, seehttp://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded fromhttp://code.google.com/p/chromedriver/downloads/list
 at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
 at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
 at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:75)
 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
 at com.example.tests.Selenium2ForChrome.main(Selenium2ForChrome.java:18)

出现这个错误的原因是因为谷歌浏览器和selenium不是原生的,需要在谷哥里面装插件,插件下载地址是http://code.google.com/p/chromedriver/downloads/list

暂时还没解决好。


3、The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://code.google.com/p/selenium/downloads/list 

该问题的错误原因和上面的一样,用IEdriver的时候也需要装插件,去http://code.google.com/p/selenium/downloads/list 下载对应的插件版本,然后修改代码如下:

[java]  view plain  copy
  1. File file = new File("C:/Selenium/iexploredriver.exe");  
  2. System.setProperty("webdriver.ie.driver", file.getAbsolutePath());  
  3. WebDriver driver = new InternetExplorerDriver();  
参考来源: http://stackoverflow.com/questions/10995314/driver-executable-must-be-set-by-the-webdriver-ie-driver-system-property


4、Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 119%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 5.98 seconds

错误原因:IE浏览器的比例调大了,按ctrl+0,可以恢复原来的大小,即可。PS:这种错误真是。。。让人无语。

 

5、My97DatePicker控件输入日期问题

之前用的是seleniumIDE自己录制的代码,结果回放的时候总是说元素找不到,整的我很头疼,后来发现一个简单的办法,就是直接把值输入日期控件的输入框当中来,

[java]  view plain  copy
  1. driver.findElement(By.id("bookDay")).clear();  
  2.         driver.findElement(By.id("bookDay")).sendKeys("2013-06-17");  

不过我觉得这个方法不好,还在寻找其他办法。

在网上找了下,有下面这个方法,问题是我看不懂。。。

http://lyh875.blog.163.com/blog/static/21428005820133192552198/

[java]  view plain  copy
  1. selenium.selectFrame("relative=up");  
  2.   //点击日期文本框  
  3.   selenium.click("days");  
  4.   //必须增加Thread.sleep(),不增加会报错,提示找不到下一条命令中的元素  
  5.   //另,尝试使用waitForPageToLoad代替,会超时出错;  
  6.   Thread.sleep(5000);  
  7.   //当前为4月,向前移两个月  
  8.   selenium.click("//div[@id='dpTitle']/div[2]");  
  9.   selenium.click("//div[@id='dpTitle']/div[2]");  
  10.   //点击2009-02-02  
  11.   selenium.click("//td[@οnclick='day_Click(2009,2,2);']"); 

现在Win7 已经应用很多了,即使是最原始的Win7 也是IE8,最新的patch后,都升到了IE9
Win7下预装高版本IE的情况下,启动IE WebDriver可能会出现:
org.openqa.selenium.WebDriverException: Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones.
  其原因是微软自IE7以后加入了Protected Mode的概念,为何如此请参考 为什么我们需要安全模式
在这种情况下,要继续启动IE WebDriver进行自动化测试,需要修改注册表,如下:
1、运行 regedit.exe
2、找到HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
3、可以看到
抛砖引玉:分享Win7 下 IE WebDriver 因保护模式无法启动的解决 - 网易杭州QA - 网易杭州 QA Team       抛砖引玉:分享Win7 下 IE WebDriver 因保护模式无法启动的解决 - 网易杭州QA - 网易杭州 QA Team
 
如果1-4号Key下面都有名叫2500的属性, 则将其值改为相同的非零值(这个地方我还没有在其他人的系统上尝试过,我自己的系统上默认的是1,2号key  2500属性值为3,3,4号key 2500属性为0,我将3,4号key的值置为了3,IE WebDriver成功启动)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值