How to save current page source in different name & folder

后端 未结 2 1485
难免孤独
难免孤独 2021-01-17 01:17

I would like to use the getPageSource() method to save the current page source under a different name in a nominated folder. e.g. save current page source as Hawai.htm unde

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-17 01:57

    Based on documentation, the getPageSource() might (depends on browser) not return correct content if page has been modified by JavaScript. If you have jQuery, you could use:​

    try (FileWriter fstream = new FileWriter("C://Holiday//Hawai.htm");
         BufferedWriter out = new BufferedWriter(fstream)) {
        String content = (String)((JavascriptExecutor)driver).executeScript("return $('html').html();"));
        out.write(content);
    } 
    catch (Exception e) {...}
    

提交回复
热议问题