【问题标题】:"org.openqa.selenium.WebDriverException" Error displayed in the code代码中显示“org.openqa.selenium.WebDriverException”错误
【发布时间】:2017-11-20 09:30:57
【问题描述】:

我无法在我的代码中找到错误“org.openqa.selenium.WebDriverException”的原因,请帮助我更好地找到并理解原因。首先我想解释一下我的代码,这是一个简单的代码,我去一个网站点击“登录”链接,然后点击一个文本“电子邮件”文本字段进行注册。我在这段代码中使用了 Page Factory。

I have 3 files.
- Base file (Before and After methods) 
- Registration File (Object repository and methods)
- Registration_Testcase File (Calling the methods)

Note: Base and Registration Testcase classes are in one package and Registration is in another package.

**Below is my code:**

基类

package testcases;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;

public class Base {

    public WebDriver driver;
    public WebDriverWait wait;

  @BeforeTest
  public void beforeTest() {
      ProfilesIni pro = new ProfilesIni();
      FirefoxProfile ffProfile = pro.getProfile("vishvesh");
      ffProfile.setAcceptUntrustedCertificates(true);
      ffProfile.setAssumeUntrustedCertificateIssuer(false);
      String base_url = "http://automationpractice.com/index.php";
      System.setProperty("webdriver.gecko.driver", "G:/Workplace/AutomationSetupFiles/Geckdriver/geckodriver.exe");
      driver = new FirefoxDriver();
      driver.get(base_url);       
  }

  @AfterTest
  public void afterTest() {
      driver.close();
  }
}

注册类

package pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;

import testcases.Base;

public class Registration extends Base{

    @FindBy(xpath="//*[@id='header']/div[2]//div[1]/a")
    WebElement SignIn;

    @FindBy(xpath="//input[@id='email_create']")
    WebElement Registration_Email;


    public Registration(WebDriver driver){
        this.driver=driver;
        PageFactory.initElements(driver, this);
    }

    public void ClickSignIn(){
        //wait.until(ExpectedConditions.visibilityOf(SignIn)).click();
        SignIn.click();
    }

    public void EnterEmail(String y){
        //wait.until(ExpectedConditions.visibilityOf(Registration_Email)).click();
        Registration_Email.click();
        Registration_Email.sendKeys(y);
    }


}

注册测试用例类

package testcases;

import org.testng.annotations.Test;

import pages.Registration;

public class Registatration_testcase extends Base{

  @Test
  public void f() {
      Registration regobj = new Registration(driver);
      regobj.ClickSignIn();
      regobj.EnterEmail("amdv1991@gmail.com");  
  }    
}

我得到的错误: 配置失败:

@BeforeTest beforeTest
org.openqa.selenium.WebDriverException: 
Build info: version: 'unknown', revision: '8c03df6', time: '2017-03-02 09:32:39 -0800'
System info: host: 'LAPTOP-SCJ4OHK5', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\VISHVE~1\AppData\Local\Temp\rust_mozprofile.XaA5YbSD8jeh, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0.3, platformVersion=10.0, moz:processID=7440, browserName=firefox, platformName=windows_nt}]
Session ID: 1ad0b6c1-bb5c-4306-afa6-b4e3dcb62ac1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325)
    at testcases.Base.beforeTest(Base.java:30)
    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:108)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
    at org.testng.TestRunner.beforeRun(TestRunner.java:626)
    at org.testng.TestRunner.run(TestRunner.java:594)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
    at org.testng.SuiteRunner.run(SuiteRunner.java:289)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
    at org.testng.TestNG.runSuites(TestNG.java:1144)
    at org.testng.TestNG.run(TestNG.java:1115)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

【问题讨论】:

  • 提示:at testcases.Base.beforeTest(Base.java:30) 的例外是get 函数。请使用调试器再次检查,尝试获取“google.com”来检查它是否有效
  • @Tuyen Nguyen,脚本在浏览器中打开网站,但它应该点击一个不会发生的链接..

标签: java selenium pom.xml browser-automation


【解决方案1】:

我似乎已经解决了这个问题,看起来有一些兼容性问题。现在我正在使用以下配置

  • 硒 3.4
  • 火狐浏览器 v48
  • 壁虎司机 17

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    相关资源
    最近更新 更多