selenium - WebDriver异常: Error: Permission denied to access property "navigator"

标签 selenium firefox selenium-webdriver selenium-firefoxdriver geckodriver

下面是遇到的“魔法”的处理:代码在 Ubuntu 16.04 上运行良好,在 Ubuntu 15.10 上运行有错误:

org.openqa.selenium.WebDriverException: Error: Permission denied to access property "navigator"
org.openqa.selenium.WebDriverException: Error: Permission denied to access property "document"

我有以下代码:

import geb.spock.GebReportingSpec
import geb.waiting.WaitTimeoutException

class LoginSpec extends GebReportingSpec {
    def "#0 go to login FB"() {
    when:
        browser.go("https://www.facebook.com/")
    then:
        delay(9)
        if (browser.title != "Facebook") {
            browser.title == "Facebook - Log In or Sign Up"
            browser.currentUrl == "https://www.facebook.com/"
            waitFor(30){
                $("#loginbutton").size() == 1
            }
            $("#email").value(Config.FB_USERNAME)
            $("#pass").value(Config.FB_PASSWORD)
            println("entered credentials")
            $("#loginbutton").click()
        }
        delay(9)
    }

    void delay(Long seconds){
        try {
            waitFor(seconds){ }
        } catch (WaitTimeoutException ignored){ }
    }
}

GebConfig.groovy:

import org.openqa.selenium.firefox.FirefoxDriver

waiting {
    timeout = 2
}
environments {
    firefox {
        driver = { new FirefoxDriver() }
    }
}
baseUrl = "https://google.com"
testReportDir = new File("$buildDir/test-reports/UT")
testResultsDir = new File("$buildDir/test-results/UT")

在 build.gradle 行

firefoxTest {
    systemProperty "webdriver.gecko.driver", "/usr/bin/geckodriver"
}

错误:

LoginSpec > #0 go to login FB FAILED
    org.openqa.selenium.WebDriverException: Error: Permission denied to access property "navigator"
    Build info: version: '3.0.0-beta4', revision: '3169782', time: '2016-09-29 10:30:04 -0700'
    System info: host: 'tb-buildagent01-infrastructure-ci', ip: '10.4.1.4', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-30-generic', java.version: '1.8.0_66-internal'
    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, appBuildId=20160606114238, version=, platform=LINUX, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0, platformVersion=4.2.0-30-generic, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Linux, device=desktop}]
    Session ID: 5af3ae72-af52-4760-9b9c-5a1261b52113
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:126)
        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:602)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:284)
        at org.openqa.selenium.remote.RemoteWebElement.getAttribute(RemoteWebElement.java:136)
        at geb.navigator.NonEmptyNavigator.setInputValue(NonEmptyNavigator.groovy:687)
        at geb.navigator.NonEmptyNavigator.setInputValues_closure40(NonEmptyNavigator.groovy:680)
        at groovy.lang.Closure.call(Closure.java:414)
        at geb.navigator.NonEmptyNavigator.setInputValues(NonEmptyNavigator.groovy:679)
        at geb.navigator.NonEmptyNavigator.value(NonEmptyNavigator.groovy:417)
        at LoginSpec.#0 go to login FB(LoginSpec.groovy:81)
    org.openqa.selenium.WebDriverException: Error: Permission denied to access property "document"
    Build info: version: '3.0.0-beta4', revision: '3169782', time: '2016-09-29 10:30:04 -0700'
    System info: host: 'tb-buildagent01-infrastructure-ci', ip: '10.4.1.4', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-30-generic', java.version: '1.8.0_66-internal'
    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, appBuildId=20160606114238, version=, platform=LINUX, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0, platformVersion=4.2.0-30-generic, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Linux, device=desktop}]
    Session ID: 5af3ae72-af52-4760-9b9c-5a1261b52113

我明白,环境有问题,但我不知道我哪里出错了?请给我建议,我该如何解决这个问题。谢谢。

最佳答案

总的来说,原因是 Ubuntu 和 Firefox 的版本不同。如果看到有人出现这样的错误,我建议从终端执行“apt-cache policy firefox”。 现在在 Ubuntu 16.04 上,您可以看到:

  Installed: 49.0+build4-0ubuntu0.16.04.1
  Candidate: 49.0+build4-0ubuntu0.16.04.1
  Version table:
 *** 49.0+build4-0ubuntu0.16.04.1 500
        500 http://ua.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages
        100 /var/lib/dpkg/status
     45.0.2+build1-0ubuntu1 500
        500 http://ua.archive.ubuntu.com/ubuntu xenial/main amd64 Packages

在 Ubuntu 15.10 上:

 Candidate: 47.0+build3-0ubuntu0.15.10.1
 Version table:
    47.0+build3-0ubuntu0.15.10.1 0
       500 http://azure.archive.ubuntu.com/ubuntu/ wily-updates/main amd64 Packages
       500 http://security.ubuntu.com/ubuntu/ wily-security/main amd64 Packages
       100 /var/lib/dpkg/status
    41.0.2+build2-0ubuntu1 0
       500 http://azure.archive.ubuntu.com/ubuntu/ wily/main amd64 Packages

这些问题必须得到解决。而回滚版本的selenium等依赖数据库也无能为力,因为在前端可能会有浏览器不支持的东西(更不用说FB了),例如:var result = window.Notification.requestPermission(callback)它是 https://developer.mozilla.org/ru/docs/Web/API/Notification/requestPermission :) 是的,你是对的,似乎(查看错误)该页面是空的 - 对于 ajax不成功。一方面,您可能会发现一个错误(并非每个客户都使用最新版本的浏览器),但就我而言 - 这是一个额外的痛苦。并更新整个系统 - 为粉丝提供娱乐,尽管您的团队中可能有一个人表现出拖延症,在这种情况下,您很幸运。

关于selenium - WebDriver异常: Error: Permission denied to access property "navigator",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40152746/

相关文章:

selenium-webdriver - 带有控件的 selenium webdriver golang sendkeys

javascript - Selenium 中的 execute_script() 有什么作用

python - 使用 Selenium 和 Python 的日历选择器

html - 收据打印机 - 从网页打印

CSS z-index 问题 : works in Firefox, 而不是 Safari?

ruby - 如何使用 selenium-webdriver 获取第三个最后值 boo?

selenium - 如何使用 Selenium 在测试之间存储值

selenium - 如何在 perl $sel->click 下使用 Selenium 点击 Javascript

css - 类 :hover works on Firefox but doesn't work on Chrome nor IE9

selenium - 使用selenium java提取dataLayer对象