1

here is my simple code of python that I wrote to save the screenshot of a webpage.

from selenium import webdriver
import time
driver=webdriver.Firefox()
driver.get("https://www.google.co.in")
driver.implicitly_wait(2)
driver.save_screenshot("D\amanulla\test.png")
driver.quit()

Though, the program running without any errors, I do not see any screenshots saved on my machine. Can someone help me on this?

2 Answers 2

3

You are missing : from "D\amanulla\test.png" and you need to escape the \ as well, so effectively the line will be either:

"D:\\amanulla\\test.png"

or

"D:/amanulla/test.png"
Sign up to request clarification or add additional context in comments.

3 Comments

you're welcome, please consider mark the answer as correct.
or just use the os builtin like this: os.path.normpath("D:\amanulla\test.png")
but adding r work os.path.normpath(r"D:\amanulla\test.png")
1

I do not see any screenshots saved on my machine

Look for a file named Dmanulla est.png in the default Downloads location for your browser... because that is what you are instructing WebDriver to do with the line:

driver.save_screenshot("D\amanulla\test.png")

Explanation:

The string "D\amanulla\test.png" will be interpreted as "Dmanulla est.png". This is because backslashes are escape sequences within Python strings. Your directory separators will be interpreted as \a (bell) and \t (tab).

Also, the : separator is missing between the drive letter and the file path, so it is treating the entire string as a filename. In the absence of a directory name, it should save to browser's default "Downloads" directory.

Solution:

driver.save_screenshot(r"D:\amanulla\test.png")

This uses a raw string so the backslashes are not interpreted as escape sequences, and it adds the missing : as the drive letter separator.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.