2015-09-08 50 views
1

如何使用Selenium webdriver在我的桌面上打開本地HTML文件?使用selenium webdriver打開本地HTML文件

我試圖像下面,但無法打開

public static String OpenStub (String stub) { 

    try { 

    driver=new FirefoxDriver(); 
    driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS); 

    driver.get("C://Users//sharmayo//Desktop//testlogin.html"); 

    return "Pass"; 
    } 
} 

回答

0

試試這樣說:

driver.get("file:///C:/Users/sharmayo/Desktop/testlogin.html"); 

UPDATE:

請先嚐試這樣最簡單的HTML文件(您TESTLOGIN .html)

<html> 
    <head> 
    </head> 
    <body> 

    <div>Hello World!</div> 

    </body> 
</html> 
+1

沒有工作得到如下錯誤文件找不到 的Firefox不能找到在/ C文件:/用戶/ sharmayo/workspace/FodB測試/結果/結果_09-08-2015 13-11-19 /截圖/ FDB-1通過Appt browser.png查看Stub。 檢查文件名是否有大寫字母或其他鍵入錯誤。 檢查文件是否被移動,重命名或刪除。 – yogesh

+0

更新了我的答案! ??你有沒有使用testlogin.html的路徑?你的testlogin.html中有什麼可以提供代碼,也許你正在鏈接到一個不存在的資源 - >首先使用testlogin.html中最簡單的html – drkthng

3

你應該使用這樣的文件地址:

driver.get("C:\\Users\\sharmayo\\Desktop\\testlogin.html"); 

代替:

driver.get("C://Users//sharmayo//Desktop//testlogin.html"); 
+0

是的,它得到了工作,非常感謝 – yogesh

相關問題