How to save current page source in different name & folder

后端 未结 2 1506
难免孤独
难免孤独 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 02:00

    getPageSource() will return a String which contains entire page source.

    In WebDriver there is no file operations available. For writing that string (page source) to separate file in required location you should use some programming language.

    class FileWrite 
    {
     public static void main(String args[])
      {
      try{
      // Create file 
      FileWriter fstream = new FileWriter("C://Holiday//Hawai.htm");
      BufferedWriter out = new BufferedWriter(fstream);
      out.write(driver.getPageSource());
      //Close the output stream
      out.close();
      }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
      }
      }
    }
    

提交回复
热议问题