java 使用 selenium webdriver 打开本地 HTML 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32451178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 20:13:49  来源:igfitidea点击:

Open A Local HTML file using selenium webdriver

javaselenium

提问by yogesh

how can I open a Local HTML file on my desktop using the Selenium webdriver?

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

I tried like below but unable to open

我试过如下但无法打开

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";
  }
}

回答by jain28

You should use file address like this:

您应该像这样使用文件地址:

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

instead of:

代替:

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

回答by drkthng

Try it this way:

试试这个方法:

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

UPDATE:

更新:

please first try the simplest html file like this (for your testlogin.html)

请先尝试像这样的最简单的 html 文件(对于您的 testlogin.html)

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

    <div>Hello World!</div>

  </body>
</html>