Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Title bar appears in middle of page during screenshots on Selenium

See below where I try to screenshot Facebook. The top bar which is normally at the top of the browser, is appearing in the middle of the screenshot.

How can I hide it, or adjust the browser so that the top bar stays up and out of the way?

I use Selenium to screenshot then I sent it to PIL to get it cropped.

Note that when this appears, I may be scrolled down quite a ways.

enter image description here

like image 939
User Avatar asked Feb 09 '23 19:02

User


1 Answers

You can manipulate the html code like deleting the class attribute of the navigation bar by this driver.execute_script("document.getElementById('blueBarNAXAnchor').setAttribute('class', '')") then it stay in the begining of the page without style. Then you can take screenshot without it. See the below, check face_1.png:

>>> driver.save_screenshot("face.png")
True
>>> driver.execute_script("document.getElementById('blueBarNAXAnchor').setAttribute('class', '')")
>>> driver.save_screenshot("face_1.png")
True

enter image description here

like image 173
Mesut GUNES Avatar answered Feb 12 '23 12:02

Mesut GUNES