【问题标题】:Whether selenium Standalone server 2.50 not support in Fire fox browser 49.0 version?selenium Standalone server 2.50是否不支持火狐浏览器49.0版本?
【发布时间】:2017-03-20 15:06:58
【问题描述】:

selenium 不支持最新的 mozilla 版本,有什么解决办法吗?

这是我的代码

package Admin_Package;

import org.openqa.selenium.WebDriver; import
org.openqa.selenium.firefox.FirefoxDriver;

public class test {



public static void main(String[] args) throws InterruptedException {
    // Download "geckodriver.exe" from https://github.com/mozilla/geckodriver/releases
    System.setProperty("webdriver.gecko.driver","D:\\ecl_ee\\jar_files\\gecko_driver\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();

    driver.get("http://www.facebook.com");

    System.out.println("Application title is ============="+driver.getTitle());

    driver.quit();
} }

如果我在下面使用 3.0.1 独立版本,则会出现错误 java.lang.IllegalStateException:驱动程序可执行文件不存在:D:\ecl_ee\jar_files\gecko_driver\geckodriver.exe 在 com.google.common.base.Preconditions.checkState(Preconditions.java:199) 在 org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:121) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116) 在 org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:37) 在 org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:95) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296) 在 org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:277) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:247) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:242) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:135) 在 Admin_Package.test.before(test.java:20) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) 在 java.lang.reflect.Method.invoke(未知来源) 在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86) 在 org.testng.internal.Invoker.invokeMethod(Invoker.java:646) 在 org.testng.internal.Invoker.invokeTestMethod(Invoker.java:823) 在 org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131) 在 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129) 在 org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112) 在 org.testng.TestRunner.privateRun(TestRunner.java:778) 在 org.testng.TestRunner.run(TestRunner.java:632) 在 org.testng.SuiteRunner.runTest(SuiteRunner.java:366) 在 org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) 在 org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) 在 org.testng.SuiteRunner.run(SuiteRunner.java:268) 在 org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 在 org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 在 org.testng.TestNG.runSuitesSequentially(TestNG.java:1225) 在 org.testng.TestNG.runSuites(TestNG.java:1075) 在 org.testng.TestNG.run(TestNG.java:1047) 在 org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126) 在 org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137) 在 org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

浏览器打开后出现这个错误

1478585217132 geckodriver INFO    Listening on 127.0.0.1:42466
Nov 08, 2016 11:36:57 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1478585217594 mozprofile::profile INFO    Using profile path C:\Users\Divya\AppData\Local\Temp\rust_mozprofile.Xge4QjcxXLSu
1478585217596 geckodriver::marionette INFO    Starting browser C:\Program Files\Mozilla Firefox\firefox.exe
1478585217605 geckodriver::marionette INFO    Connecting to Marionette on localhost:2185
1478585219168 Marionette  INFO    Listening on port 2185
1478585221536 Marionette  INFO    startBrowser 2a9015b9-cac1-4641-839d-8f9279055519
Nov 08, 2016 11:37:01 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: http://reventics.infoversity.in/app/services/sharedProperties.js, line 13: unreachable code after return statement
JavaScript warning: http://reventics.infoversity.in/app/services/sharedProperties.js, line 13: unreachable code after return statement
Application title is =============Reventics
[Child 1708] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2052
Nov 08, 2016 11:37:09 AM org.openqa.selenium.os.UnixProcess destroy
SEVERE: Unable to kill process with PID 6120

前、后套件类

package Admin_Package;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeSuite;
public class BA_Admin {
public static WebDriver driver;
@BeforeSuite
public void beforeSuite() throws InterruptedException {           
System.setProperty("webdriver.gecko.driver","D:\\ecl_ee\\jar_files\\gecko_driver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("URL");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@AfterSuite     
public void afterSuite() throws Exception { 
driver.quit();
}
}

扩展类

package Admin_Package;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Role_Add extends Admin_Package.BA_Admin{
@BeforeTest
public void login() throws InterruptedException {
driver.findElement(By.xpath(".//*[@id='txtUsername']")).sendKeys("venkatm");
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[@id='txtPassword']")).sendKeys("Password@123");
Thread.sleep(5000);
driver.findElement(By.xpath("html/body/div[2]/div/form/div/div/div[2]/div/button[1]")).click();
Thread.sleep(5000);
System.out.println("Login Test Case Passed"); 
} 
@Test
public void link1() throws InterruptedException { 
driver.findElement(By.xpath("html/body/div[1]/aside/section/ul[1]/li[1]")).click();
Thread.sleep(5000);
}  
}
}

运行该类后出现以下错误

1478588994124 geckodriver INFO    Listening on 127.0.0.1:36811
Nov 08, 2016 12:39:54 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1478588994625 mozprofile::profile INFO    Using profile path C:\Users\Divya\AppData\Local\Temp\rust_mozprofile.9LNcRBy7LvnX
1478588994628 geckodriver::marionette INFO    Starting browser C:\Program Files\Mozilla Firefox\firefox.exe
1478588994637 geckodriver::marionette INFO    Connecting to Marionette on localhost:3453
1478588996301 Marionette  INFO    Listening on port 3453
1478588998908 Marionette  INFO    startBrowser 533a5574-8667-4d6a-8455-b78be6709d83
Nov 08, 2016 12:39:59 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: http://reventics.infoversity.in/app/services/sharedProperties.js, line 13: unreachable code after return statement
JavaScript warning: http://reventics.infoversity.in/app/services/sharedProperties.js, line 13: unreachable code after return statement
[Utils] Attempting to create D:\ecl_ee\Projects\Reventics\test-output\Default suite\Default test.html
[Utils]   Directory D:\ecl_ee\Projects\Reventics\test-output\Default suite exists: true
[Utils] Attempting to create D:\ecl_ee\Projects\Reventics\test-output\Default suite\Default test.xml
[Utils]   Directory D:\ecl_ee\Projects\Reventics\test-output\Default suite exists: true
FAILED CONFIGURATION: @BeforeTest login
java.lang.NullPointerException
at Admin_Package.Role_Add.login(Role_Add.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143)
at org.testng.TestRunner.beforeRun(TestRunner.java:656)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1225)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1150)
at org.testng.TestNG.runSuites(TestNG.java:1075)
at org.testng.TestNG.run(TestNG.java:1047)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

SKIPPED CONFIGURATION: @AfterTest Create_Role
SKIPPED: link1

谢谢,

迪维亚

【问题讨论】:

  • 是的,你应该看到这个问题:Here
  • 错误提示“驱动程序可执行文件不存在:D:\ecl_ee\jar_files\gecko_driver\geckodriver.exe”。您真的将 geckodriver.exe 保存在上述位置吗?
  • 这似乎是您在 Firefox 浏览器中安装的插件问题。浏览所有安装的插件。 support.mozilla.org/en-US/questions/1006356。卸载或更新导致问题的插件。
  • 我不明白这个问题。对框架不太了解。从跟踪中,我知道引发了 NullPointerException “配置失败:@BeforeTest login java.lang.NullPointerException at Admin_Package.Role_Add.login(Role_Add.java:18)”。检查异常的原因是什么。是因为该课程在其他课程之前运行吗?还是在登录方法中,找不到元素?不太确定。
  • 虽然我不确定为什么会触发 NullPointerExcpetion,但我建议检查以下内容。 1.驱动对象是否不为空? 2. 是否找不到用户名字段? 3. 是否找不到密码字段?只需按如下方式使用 print 语句。 1. sysout 驱动 2. sysout driver.findElement(By.xpath(".//*[@id='txtUsername']")) 3. sysout driver.findElement(By.xpath(".//*[@id ='txtPassword']")) 并查看是否正在重新调整 NullPointer 或对象。同样适用于登录方法中的所有元素

标签: java eclipse selenium selenium-webdriver


【解决方案1】:

创建一个局部变量会导致所有的麻烦。

WebDriver driver = new FirefoxDriver();

在对象创建中删除WebDriver引用,所以引用将被添加到全局driver对象中,以便子类可以引用。

【讨论】:

    猜你喜欢
    • 2017-03-03
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多