0

Sorry for asking this question which may sound silly, but I am a beginner and I am pretty stuck here.

I have made a script in Python that does screenshots at a certain moment using Selenium library. All this thing is in a for loop and every screenshot has a different filename. So, the problem is that when Python gets to the line meant to save the file to a specific location, the screenshot doesnt't get saved because the extension gets on a new line after the file name.

The code is the following:

screenshot = 'D:\\SCREENSHOTS\\' + filename + '.png'
driver.get_screenshot_as_file(screenshot)

The output is the following:

D:\SCREENSHOTS\filename
.png

How can I put .png on the same line right after filename?

Thank you in advance!

  • What is `filename` in your case? Can you show the output of `print(repr(filename))` – Leonard Sep 02 '21 at 15:31
  • Filename is the name of a local pdf that gets uploaded to a site from my pc. After the upload I run the screenshot command to get sure that it was uploaded properly. Let's say 123.pdf. If I delete '.png', the output is D:\SCREENSHOTS\123.pdf. If I put + '.png', then it gets to a new line. – georgeionescu93 Sep 02 '21 at 15:43
  • This really shouldn't happen if there's no kind of line break in the string. Can you try printing this so we can be sure there's no line break hidden in filename? (`print(repr(filename))`) – Leonard Sep 02 '21 at 15:49

0 Answers0