2

I'm using Splinter (in Chrome browser) to take screenshots of website pages. I am naming the files exactly as I want them but unique strings are being added to the end of my filenames (eg, "filename2k3j39.png"). I haven't found anything in the Splinter or Selenium documentation that indicates that these are added. What part of the program is adding the Unique Ids? Windows 10, Chromedriver, Selenium, Splinter?

I've checked my Chrome settings and don't see anything. Files are saved as a PNG so it's not a PDF setting.

from splinter import Browser
executable_path = {'executable_path':r'C:\Users\me\chromedriver.exe'}
browser = Browser('chrome', **executable_path)

screenshot_path = browser.screenshot('C:/Home/Progress/me/screen shots/' + my_var + '/web/www_' + name + ' (' + now.strftime("%Y-%m-%d") + ')', full=True)

The result is www_Name (1-1-2000)2k3j39.png instead of www_Name (1-1-2000).png

dbgg
  • 23
  • 5
  • It looks like you aren't ever saving the file so it's auto generating a temporary file name for you. Have you instead tried `screenshot_path = browser.screenshot('C:/Home/Progress/me/screen shots/' + my_var + '/web/www_' + name + ' (' + now.strftime("%Y-%m-%d") + ').png', full=True)` including the `.png` file extension at the end? – Michael Platt May 06 '19 at 17:50
  • So that's interesting. I added the .png and now instead of the Unique ID being 8 characters it's now 11 chars long... – dbgg May 06 '19 at 18:23
  • It looks like there are a couple odd things going on. Your date is formatted to use `-`(dash) and the file output name is coming out with `.`(dot) instead. Have you tried doing something simple like not using a date in your name at all just to make sure it works. Also, If you are on Windows do you need to declare the path for the screenshot to be a `\`(backslash) instead of a `/`(front slash)? I would make a directory with a simple path (ie. No spaces between folder names) and try that out and see what happens. – Michael Platt May 06 '19 at 18:39

1 Answers1

0

So, I worked out what was happening here .... by debugging the splinter library I could see that it doesn't match the document. The library takes the filename, uses that as a prefix to the python function to create a temporary file and adds the undocumented parameter suffix (which defaults to png). It then returns the filename from the function.

So, I modified my code to: filename = tdir + datetime.date.today().strftime('%Y-%b-%d-image.png') actualName = element.screenshot(filename, suffix='.png', full=False) move(actualName, filename)

I also had issues with the python os libraries for rename and remove on windows, hence I am using shutil.move

Bryan
  • 295
  • 1
  • 2
  • 9