How to disable screenshot previews in Chrome while using screenshot_as_png in selenium?

Viewed 215

Chrome seems to display a small preview of the element whose screenshot is being taken by screenshot_as_png on the top right corner.

Note: The following code will take repeated screenshots of Google's logo on its search page. Chrome tends to darken the background during this.

Epileptic warning: Your browser will flash rapidly while running the following code.

You can move the driver.find_element_by_xpath('//*[@id="hplogo"]').screenshot_as_png outside the while loop to avoid flashing but you will have to be quick to see the screenshot preview...

from selenium import webdriver

driver = webdriver.Chrome(executable_path=) #enter your executable path

driver.get('https://google.com')

while True:
    driver.find_element_by_xpath('//*[@id="hplogo"]').screenshot_as_png

Before taking the screenshot:

enter image description here

Preview during screenshot:

enter image description here

Is there a way to disable this preview via options during creating a driver object?

Specifications:

  • Chrome version: 84.0.4147.89 (Official Build) (64-bit)
  • Chrome driver version: 84.0.4147.30 32-bit
  • Selenium version: 3.141.0

Additional information:

(This information is secondary information that isn't necessary to know to answer this question)

I am trying to apply Q-learning and NEAT algorithm (separately) to automate the chrome dino game. I am taking repeated screenshots of the canvas in that game and later processing the image using cv2.

As you can see by running the above code, this causes the browser to flash rapidly. Previously, I was trying to do this in Firefox on the "https://chromedino.com/" but I later decided to switch to Chrome to play the original game instead of a replica whose faithfulness to the original is questionable.

I didn't face any flashing/screenshot issues in Firefox.


Update: I haven't yet found a solution to this problem. Instead, I used the extracted dino game from Chrome and opened it in Firefox.

0 Answers
Related