How to use Selenium WebDriver on local webpage (on my PC) instead of one located somewhere online?

前端 未结 6 1980
小鲜肉
小鲜肉 2020-11-27 18:58

I want to use Selenium WebDriver on a webpage that I have on my hard disc. I\'ve tried to something like:

selenium =         


        
相关标签:
6条回答
  • 2020-11-27 19:23

    For those of us using java.nio, we can also do the following:

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

    ...where filePath is an object of type java.nio.file.Path and represents an absolute path.

    0 讨论(0)
  • 2020-11-27 19:34

    Selenium Version: 3.141.59

    Use this webdriver.get("file:///D:/folder/abcd.html") get failed.

    Instead of webdriver.get("///D:/folder/abcd.html") get successfully.

    0 讨论(0)
  • 2020-11-27 19:35

    This can also be done with a relative file:

    Path sampleFile = Paths.get("sample.html");
    driver.get(sampleFile.toUri().toString());
    
    0 讨论(0)
  • 2020-11-27 19:41

    Try using this method:

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

    (or)

    selenium = new WebDriverBackedSelenium(driver, "file:///D:/folder/abcd.html");
    
    0 讨论(0)
  • 2020-11-27 19:42

    You can always drag and drop html file from your PC on open web browser during selenium session and see how file path looks. In my case it is:

    webdriver.get("file:///C:/Users/Desktop/Some%20%E2%80%93%20file%20on%20the%20PC.html")
    
    0 讨论(0)
  • When you call the driver.get(URL) method, WebDriver looks for HTTP request using as base javascript, Therefore, refering to a website as a path, that task won't be possible.

    But it will be possible if you : 1st- Install Apache WebServer (let's say) on your marchine. 2nd- Upload or expose to the WebServer, that web application (dispatcher.html) 3rd- Try recording and executing your testcases on [http://localhost:8080/dispatcher.html] (8080 is the default port but you can configure it to other).

    0 讨论(0)
提交回复
热议问题