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
File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
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
driver.findElement(By.id("bookDay")).clear();
        driver.findElement(By.id("bookDay")).sendKeys("2013-06-17");  

不过我觉得这个方法不好,还在寻找其他办法。
在网上找了下,有下面这个方法,问题是我看不懂。。。

http://lyh875.blog.163.com/blog/static/21428005820133192552198/
[java] view plain copy
selenium.selectFrame("relative=up");
  //点击日期文本框
  selenium.click("days");
  //必须增加Thread.sleep(),不增加会报错,提示找不到下一条命令中的元素
  //另,尝试使用waitForPageToLoad代替,会超时出错;
  Thread.sleep(5000);
  //当前为4月,向前移两个月
  selenium.click("//div[@id=‘dpTitle‘]/div[2]");
  selenium.click("//div[@id=‘dpTitle‘]/div[2]");
  //点击2009-02-02
  selenium.click("//td[@onclick=‘day_Click(2009,2,2);‘]");  
时间: 2024-08-26 11:13:29

selenium使用中遇到的问题的相关文章

浅析selenium的PageFactory模式

前面的文章介绍了selenium的PO模式,见文章:http://www.cnblogs.com/qiaoyeye/p/5220827.html.下面介绍一下PageFactory模式. 1.首先介绍FindBy类: For example, these two annotations point to the same element: @FindBy(id = "foobar") WebElement foobar; @FindBy(how = How.ID, using = &q

Selenium的坑

一.关于检查元素(右键点击检查.或者F12)复制xpath. 今天遇到的坑是,当下面的窗口按照第二种方式锁定在测试页面右边或下面时,会导致测试页面出现多余的元素.此时,复制出的xpath会有误.所以,建议采用第一种方式,在独立的窗口打开元素获取窗口.如下图: 二.关于悬停 当鼠标光标移入某个元素时,会发现元素有变化.此时需要添加悬停即hover的关键字驱动.另外很重要的是,悬停在内部机制已经写好了固定的等待时间为0.5s,0.5秒后悬停即看不到,也找不到其元素定位.因此此时一定不要再设置等待(s

浅析selenium的page object模式

selenium目前比较流行的设计模式就是page object,那么到底什么是page object呢,简单来说,就是把页面作为对象,在使用中传递页面对象,来使用页面对象中相应的成员或者方法,能更好的提现java的面向对象和封装特性,首先看一下官网的解释: Page Object Design Pattern Page Object is a Design Pattern which has become popular in test automation for enhancing tes

selenium python --自动表单填写--学习笔记

因为公司业务的需要,要在公司内部网上(jsp网站)系统中做大量的重复操作,之前也用过如"按键精灵"或"Auto_ACN"之类的自动操作软件.但是这些东西不但脚本编写困难(主要是对网页上特定原素的定位等)运行的时候还占用整台电脑,不能有任何干扰.也考虑过使用python 来直接模拟浏览器,自动构建表单数据发送来自动操作,但公司这个破网站,一大堆的frame 一大堆的javascript 跟踪了几次还是没有找出form的post地址和需要发送的表单数据. 终于,在学习自

Selenium + python的自动化框架搭建

selenium是一个web的自动化测试工具,和其它的自动化工具相比来说其最主要的特色是跨平台.跨浏览器.支持windows.linux.MAC,支持ie.ff.safari.opera.chrome等.此外还有一个特色是支持分布式测试用例的执行,可以把测试用例分布到不同的测试机器的执行,相当于分发机的功能. 关于selenium的原理.架构.使用等可以参考其官网的资料,这里记录如何搭建一个使用python的selenium测试用例开发环境.其实用python来开发selenium的方法有2种:

关于在selenium 中 webdriver 截图操作

package prictce; import java.io.File; import java.io.IOException; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.We

python selenium 处理时间日期控件(十五)

测试过程中经常遇到时间控件,需要我们来选择日期,一般处理时间控件通过层级定位来操作或者通过调用js来实现. 1.首先我们看一下如何通过层级定位来操作时间控件. 通过示例图可以看到,日期控件是无法输入日期,点击后弹出日期列表供我们选择日期,自己找了一个日期控制演示一下,通过两次定位,选择了日期 #-*- coding:utf-8 -*- import time from selenium import webdriver driver = webdriver.Chrome() driver.get

selenium+python在mac环境上的搭建

前言 mac自带了python2.7的环境,所以在mac上安装selenium环境是非常简单的,输入2个指令就能安装好 需要安装的软件: 1.pip 2.selenium2.53.6 3.Firefox44.dmg 4.Pycharm (环境搭配selenium2+Firefox46及以下版本兼容,selenium3+Firefox47+geckodriver) 一.selenium安装 1.mac自带了python2.7,python里面又自带了easy_install工具,所以安装pip用e

Selenium+Java+Eclipse 自动化测试环境搭建

一.下载Java windows java下载链接 https://www.java.com/zh_CN/download/win10.jsp 二.安装Java 安装好后检查一下需不需要配置环境变量,现在java 8已经不用配置环境变量了,直接在命令行输入:java -version 三.下载和安装Eclipse windows Eclipse下载链接 https://www.eclipse.org/downloads/ 你也可以下载绿色版 四.下载selenium,然后解压 selenium