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。

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

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

WebDriver driver = new FirefoxDriver();

2. java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, seehttps://github.com/mozilla/geckodriver.

原因是使用了最新的selenium webdriver版本Selenium 3.x,此版本不支持直接启动firefox,必须要先设置SystemProperty

下载最新版本的geckoDriver https://github.com/mozilla/geckodriver/releases

System.setProperty("webdriver.gecko.driver", "E:/AndroidWorkspace/SeleniumTest/geckodriver-v0.19.1-win64/geckodriver.exe");

3.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

4.WebDriver driver = new FirefoxDriver();时老是编译出错:FirefoxDriver cannot be resolved to a type。

试过很多方法都不行,最后把eclipse版本更新后就正常了。

类似的很多问题可能都跟编译器有关系,所以尽量保持用最新的编译器。

5.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 下载对应的插件版本,然后修改代码如下:

    1. File file = new File("C:/Selenium/iexploredriver.exe");
    2. System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
    3. WebDriver driver = new InternetExplorerDriver();

6.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:这种错误真是。。。让人无语。

7.My97DatePicker控件输入日期问题

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

    1. driver.findElement(By.id("bookDay")).clear();
    2. driver.findElement(By.id("bookDay")).sendKeys("2013-06-17");

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

    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[@onclick='day_Click(2009,2,2);']");

8.baiduInputText.sendKeys("sdfs");老是编译出错:The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)。

写成这样就可以了:baiduInputText.sendKeys(new String[] {"sdfs"});

9.Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:116)
    at java.util.Optional.orElseGet(Unknown Source)
    at org.openqa.selenium.firefox.FirefoxOptions.getBinary(FirefoxOptions.java:218)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:155)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:98)
    at com.hejing.selenium.Selenium2.main(Selenium2.java:24)

报这个错误同样是因为firefox的安装路径与默认安装路径不一致所致,不一致情况都需要单独进行设置firefox的安装路径:System.setProperty("webdriver.firefox.bin", "D:/software/Mozilla Firefox/firefox.exe");

10.Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:754)

意思是我们缺少了设置ie浏览器的驱动,下载ie的驱动然后再配置到工程中即可。

System.setProperty("webdriver.ie.driver", "E:/Java workspace/SeleniumTest/IEDriverServer_x64_3.8.0/IEDriverServer.exe");

11.Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for

不能创建session会话异常,在启动ie浏览器的时候错误:所有区域的保护模式设置不一致。

然后就去查阅了文档:https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

说的是:在Windows Vista或Windows 7上的IE 7或更高版本上,必须将每个区域的保护模式设置设置为相同的值。 值可以打开或关闭,只要每个区域相同。 要设置保护模式设置,请从工具菜单中选择“Internet选项...”,然后单击安全选项卡。 对于每个区域,在标签为“启用保护模式”的标签底部将出现一个复选框。
另外,对于IE 10及更高版本,必须禁用“增强保护模式”。 此选项位于“Internet选项”对话框的“高级”选项卡中。

按照说明操作果然能正常运行了。

12.Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4444 [/127.0.0.1] failed: Connection refused: connect
Caused by: java.net.ConnectException: Connection refused: connect

异常原因是没有启动远程服务器,客户端与服务端没法建立连接。

运行远程服务器:java -jar E:\selenium-server-standalone-3.8.1.jar

Selenium问题总结的更多相关文章

  1. Python爬虫小白入门(四)PhatomJS+Selenium第一篇

    一.前言 在上一篇博文中,我们的爬虫面临着一个问题,在爬取Unsplash网站的时候,由于网站是下拉刷新,并没有分页.所以不能够通过页码获取页面的url来分别发送网络请求.我也尝试了其他方式,比如下拉 ...

  2. Selenium的PO模式(Page Object Model)[python版]

     Page Object Model 简称POM  普通的测试用例代码: .... #测试用例 def test_login_mail(self): driver = self.driver driv ...

  3. selenium元素定位篇

    Selenium webdriver是完全模拟用户在对浏览器进行操作,所有用户都是在页面进行的单击.双击.输入.滚动等操作,而webdriver也是一样,所以需要我们指定元素让webdriver进行单 ...

  4. selenium自动化基础知识

    什么是自动化测试? 自动化测试分为:功能自动化和性能自动化 功能自动化即使用计算机通过编码的方式来替代手工测试,完成一些重复性比较高的测试,解放测试人员的测试压力.同时,如果系统有不份模块更改后,只要 ...

  5. 幼儿园的 selenium

    from selenium import webdriver     *固定开头     b=webdriver.Firefox()              *打开火狐浏览器    browser. ...

  6. 使用selenium编写脚本常见问题(一)

    前提:我用selenium IDE录制脚本,我用java写的脚本,如果大家想看的清楚明白推荐java/Junit4/Webdriver 我用的是java/TestNG/remote control 1 ...

  7. 关于selenium RC的脚本开发

    第一.需要录制脚本,找个我也不说了.就是在firefox下下载一个selenium-IDE并且安装. 第二.在工具里找到selenium-IDE点击运行. 第三.默认是红色按钮点击状态的,接下来随便你 ...

  8. 基于python的selenium自动化测试环境安装

    1. Python2安装 官方网站:https://www.python.org/downloads/ (python3或新版本已经默认集成了pip包和path,安装的时候打勾就行,可以直接跳过下面第 ...

  9. Selenium+python 配置

    1. 安装python, www.python.org. 下载最新的python,应该是32位的.注意配置环境变量. 2. 安装PIP(pip是一个以Python计算机程序语言写成的软件包管理系统). ...

  10. selenium 使用action进行鼠标,键盘操作

    <!--test.html--> <html> <head> <title>Set Timeout</title> <script&g ...

随机推荐

  1. .NET Standard - 揭秘 .NET Core 和 .NET Standard[转自MSDN]

    作为 .NET 系列的最新成员,.NET Core 和 .NET Standard 的概念及其与 .NET Framework 的区别并不十分明确.在本文中,我将准确介绍每个产品及其适用场景. 在详细 ...

  2. C语言 · 图形输出

    算法提高 图形输出   时间限制:1.0s   内存限制:512.0MB      编写一程序,在屏幕上输出如下内容: X | X | X ---+---+--- | | ---+---+--- O ...

  3. fastjson常用操作

    一. fastjson生成json字符串(JavaBean,List<JavaBean>,List<String>,List<Map<String,Object&g ...

  4. 使用模板方法模式简化JDBC操作

    在使用JDBC时,会重复的写很多重复的代码,例如 Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; S ...

  5. Android——onCreate( )方法详解(转)

    android开发之onCreate( )方法详解 onCreate( )方法是android应用程序中最常见的方法之一,那么,我们在使用onCreate()方法的时候应该注意哪些问题呢? 先看看Go ...

  6. MapReduce的InputFormat过程的学习

    转自:http://blog.csdn.net/androidlushangderen/article/details/41114259 昨天经过几个小时的学习,把MapReduce的第一个阶段的过程 ...

  7. 错题0920-java

    1.java如何接受request域中的参数? A:request.getRequestURL() B:request. getAttribute() C:request.getParameter() ...

  8. 第二百六十二节,Tornado框架-cookie

    Tornado框架-cookie Cookie 是网站用来在客户端保存识别用户的一种小文件.一般来用库可以保存用户登 录信息.购物数据信息等一系列微小信息. self.set_cookie()方法,创 ...

  9. ChemDraw Prime 15怎么绘制立体化学结构

    众所周知,ChemDraw化学工具的最新版本是ChemOffice 15,其下还有三个适合不同用户的版本,下文详细指导如何使用入门版本ChemDraw Prime 15绘制立体化学结构. 立体化学结构 ...

  10. Maven项目POM.xml详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...