2016-10-17 170 views
2

我寫了下面的代碼來捕獲使用Java腳本的網頁的整個屏幕截圖。權限被拒絕訪問屬性「H」

我使用: 的Firefox版本: 49.0.1 Chrome的版本: 54.0.2840.59米 硒版本: 3.0.0 OS: Win10 64位 的Java : 1.8

import java.io.File; 
import java.io.IOException; 

import org.apache.commons.io.FileUtils; 
import org.openqa.selenium.JavascriptExecutor; 
import org.openqa.selenium.OutputType; 
import org.openqa.selenium.TakesScreenshot; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class ScreenCapture { 

    public static void main(String[] args) throws IOException { 
     System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe"); 
     WebDriver driver = new FirefoxDriver(); 
     driver.get("https://www.flipkart.com/"); 
     driver.manage().window().maximize(); 
     JavascriptExecutor js = (JavascriptExecutor) driver; 
     js.executeScript("window.scrollTo(0, document.body.scrollHeight)"); 
     File capture = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); 
     FileUtils.copyFile(capture, new File("C:\\Users\\Vishvambruth JT\\Desktop\\FlipKart.jpg")); 
    } 
} 

網頁將滾動但代碼突然停止,出現下面的錯誤。能否請你幫忙。

1476679740598 geckodriver INFO Listening on 127.0.0.1:38310 
Oct 16, 2016 11:49:00 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end 
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 
1476679741083 mozprofile::profile INFO Using profile path C:\Users\VISHVA~1\AppData\Local\Temp\rust_mozprofile.h4P3qq7Ekmrz 
1476679741083 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe 
1476679741083 geckodriver::marionette INFO Connecting to Marionette on localhost:50064 
1476679742059 Marionette INFO Listening on port 50064 
1476679743366 Marionette INFO startBrowser 6f833edf-0ff4-4f1f-869c-1de62f8626a9 
Oct 16, 2016 11:49:03 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
INFO: Detected dialect: W3C 
Exception in thread "main" org.openqa.selenium.WebDriverException: Permission denied to access property "H" 
Build info: version: 'unknown', revision: '350cf60', time: '2016-10-13 10:43:56 -0700' 
System info: host: 'LAPTOP-JUUNTJIC', ip: '10.0.0.112', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101' 
Driver info: org.openqa.selenium.firefox.FirefoxDriver 
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, firefoxOptions={args=[], prefs={}}, appBuildId=20160922113459, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=9960, browserVersion=49.0.1, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=windows_nt, device=desktop}] 
Session ID: 6f833edf-0ff4-4f1f-869c-1de62f8626a9 
    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:601) 
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:537) 
    at ScreenCapture.main(ScreenCapture.java:19) 
+0

使用wires.exe代替geckodriver.exe,並在您的本地系統中將其命名爲wire而不是geckodriver –

+0

@PotnuruRavi,您希望我將geckodriver.exe文件重命名爲wires.exe並更改代碼,如下所示:System .setProperty( 「webdriver.wires.driver」, 「C:\\蝕\\驅動\\ wires.exe」); –

+0

,但不要將該文件另存爲wires.exe。你可以將它保存爲導線 –

回答

0

我得到了Selenium Web Driver 3.0.1相同的錯誤。 切換到版本2.53.1時,問題消失了。

0

我也有這個問題,經過一番研究,我可以說這不是硒的問題。這是gecko驅動程序的問題。你可以用chrome運行它,它會正常工作。

0

只需更新到Firefox夜晚,它會工作。

Firefox Night可以在https://www.mozilla.org/en-US/firefox/channel/desktop/(標有Beta的那個)上找到。

最好使用帶有最新Firefox Night版本的最新webdriver版本(開發和代碼問題的所有代碼和努力都集中在該同步上,當然這很有意義爲了更好地覆蓋更新的最終用戶場景)。

相關問題