如何在本地(在我的电脑上)网页上使用selenium webdriver而不是在www上找到somwhere?

我必须在我硬盘上的网页上使用selenium webdriver。 我尝试过类似的东西:

selenium = new WebDriverBackedSelenium(driver, "C:\\...dispatcher.html"); 

而不是正常的:

 selenium = new WebDriverBackedSelenium(driver, "http://www.dunnowhattodo.org"); 

但它不起作用(我得到错误“未知协议:c”)

它甚至可能吗? 我有点seleniumwebdriver的新用户,所以它可能是一个愚蠢的问题,但仍然我会appriciate每一个帮助,我会得到:)

尝试使用此方法:

 webdriver.get("file:///D:/folder/abcd.html"); 

(要么)

 selenium = new WebDriverBackedSelenium(driver, "file:///D:/folder/abcd.html"); 

这也可以使用相对文件来完成:

 Path sampleFile = Paths.get("sample.html"); driver.get(sampleFile.toUri().toString()); 

当您调用driver.get(URL)方法时,WebDriver使用基本javascript查找HTTP请求,因此,将网站称为路径,该任务将无法执行。

但是如果你有可能:第一 – 在你的游艇上安装Apache WebServer(让我们说)。 第2步 – 上传或向WebServer公开,该Web应用程序(dispatcher.html)第3步 – 尝试在[http:// localhost:8080 / dispatcher.html]上记录并执行测试用例(8080是默认端口,但您可以配置它到其他)。

对于我们这些使用java.nio ,我们也可以执行以下操作:

 webdriver.get("file:\\\\\\" + filePath); 

…其中filePathjava.nio.file.Path类型的对象,表示绝对路径。