The title bar is displayed in the middle of the page during screenshots on Selenium

See below where I am trying to take a screenshot of Facebook. The top bar, which is usually located at the top of the browser, appears in the middle of the screen.

How can I hide it or configure the browser so that the top panel remains on the side and is not in the way?

I use Selenium for a screenshot, then I sent it to PIL to be cropped.

Please note that when this appears, I can scroll quite far.

enter image description here

+4
source share
3 answers

html-, , driver.execute_script("document.getElementById('blueBarNAXAnchor').setAttribute('class', '')"), . . . , 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

+4

, , .

driver.maximize_window() driver.get driver.save_screenshot.

+2

reduce . 500 , , .

This is because when the browser height is below 500 pixels, the top bar disappears from the screen. Above this height, the top bar appears in the browser viewing window, hanging above the news feed. You can also try this manually.

Java

driver.manage().window().setSize(new Dimension(1024, 500));

PYTHON

driver.set_window_size(300, 500)

The above code is in JAVA. But I believe you can find the python equivalent.

NOTE. I have a screen resolution of 1366x768. Thus, the value of 500px can vary. But you definitely need to reduce the height.

+2
source

Source: https://habr.com/ru/post/1611694/


All Articles