How to click a web browser button using python?
Solution 1
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()
Solution 2
You could look into PyAutoGUI. You can automate hotkeys, clicks, etc.
pyautogui.click(x=moveToX, y=moveToY, clicks=num_of_clicks, interval=secs_between_clicks, button='left')
It does have a screenshot function, though I'm not sure if it is what you are looking for since you wanted to use Chrome's built-in function
pyautogui.screenshot('foo.png')
or if you only wanted a certain part of the screen/webpage
pyautogui.screenshot(region=(0,0, 300, 400))
Related videos on Youtube
anaghapramesh
Updated on June 04, 2022Comments
-
anaghapramesh almost 2 years
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.
-
Bumsik Kim almost 5 yearsUse WebDriver or Puppeteer.
-
chickity china chinese chicken almost 5 yearsThere's Sikuli too
-
-
Reedinationer almost 5 yearsI believe PyAutoGUI has a screenshot function too that should probably be included in your post!
-
Matt M almost 5 yearsI didn't include it originally since it really isn't Chrome's screenshot function. But I added it in
-
Reedinationer almost 5 yearsYeah, true. OP could potentially have it in full screen mode (with
F11
) in which case it would be the same though. Good call to include the optionalregion
argument though. I think between the two answers the problem should be easily solvable!