Webdriver Screenshot

后端 未结 12 810
南方客
南方客 2020-11-30 00:57

When taking a screenshot using Selenium Webdriver on windows with python, the screenshot is saved directly to the path of the program, is there a way to save the .png file t

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 01:29

    I understand you are looking for an answer in python, but here is how one would do it in ruby..

    http://watirwebdriver.com/screenshots/

    If that only works by saving in current directory only.. I would first assign the image to a variable and then save that variable to disk as a PNG file.

    eg:

     image = b.screenshot.png
    
     File.open("testfile.png", "w") do |file|
      file.puts "#{image}"
     end
    

    where b is the browser variable used by webdriver. i have the flexibility to provide an absolute or relative path in "File.open" so I can save the image anywhere.

提交回复
热议问题