使用selenium的java出错:预期[object Undefined]

时间:2017-04-18 12:28:32

标签: java selenium firefox selenium-webdriver geckodriver

  

我不明白为什么我得到错误预期[object Undefined] undefined为一个字符串

这是脚本java LoginToGmail.java

<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
</head>

<body ng-controller="MainCtrl">
  <select ng-model="device.remote" ng-repeat="remoteID in device.remoteIDs">
    <option value="{{ remoteID.id }}">{{ remoteID.name }}</option>
  </select>
  <select ng-model="device1.remote" ng-repeat="remoteID in device1.remoteIDs">
    <option value="">select</option>
    <option value="{{ remoteID.id }}">{{ remoteID.name }}</option>
  </select>
  <script>
    var app = angular.module('plunker', []);

    app.controller('MainCtrl', function($scope) {


      $scope.device = {
        "remote": "1",
        "remoteIDs": [{
          "id": "1",
          "name": "TEST"
        }]
      };

      $scope.device1 = {
        "remote": "",
        "remoteIDs": [{
          "id": "1",
          "name": "TEST"
        }]
      };


    });
  </script>
</body>

</html>

完整堆栈错误是:

WebDriver driver;
driver =new FirefoxDriver();
driver.manage().window().maximize();
driver.navigate().to("http://www.facebook.com");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement act= driver.findElement(By.id("email"));
act.sendKeys("rupali9392@gmail.com");

1 个答案:

答案 0 :(得分:10)

要使用Selenium 3.x,Mozila Firefox 52.x,您需要从here下载最新的gecko驱动程序,并提供gecko驱动程序的绝对路径,如下所示:

//Mozila Firefox
System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
WebDriver driver =  new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http:\\gmail.com");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.id("Email")).sendKeys("your_id");