How to click a web browser button using python?

anaghapramesh picture anaghapramesh · May 15, 2019 · Viewed 9.1k times · Source

I am new to Python and currently I am working on a program to capture full page screen and email it to specific persons. I have done the email part well. But I am finding difficulty to find a python script that clicks on "Full Page Screen Capture" button in Google Chrome using Python Script. May I know is there a way for that? I have to take the screenshot by clicking "Full Page Screen Capture" button only. It will be a great help if someone could help me. Thanks in advance!

NOTE: Requesting to kindly note that, I DON'T WANT TO TAKE SCREENSHOT! Screenshot only takes the contents available on that particular screen. "Full Page screen Capture" button helps to capture the entire web page even if it is not visible in screen. MAY I HAVE A SCRIPT WHICH HELPS ME TO CLICK ON THAT BUTTON IN CHROME?

I have searched for script that clicks a web browser button. Unfortunately, I could only find scripts that helps to click web page button.

Answer

MrKioZ picture MrKioZ · May 15, 2019

There is a python library/module called selenium that allows you to automate your browser and supports multiple web browsers such as Chrome, Firefox and more.

You can get started by installing selenium using pip install selenium and then following the instructions included above to get drivers.

Here is a quick starting script for taking a screenshot (in this example i will be using Chrome)

from selenium import webdriver

browser = webdriver.Chrome()

browser.get('https://python.org')
browser.save_screenshot("screenshot.png")

browser.close()