How to click a web browser button using python?

12,744

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))
Share:
12,744

Related videos on Youtube

anaghapramesh
Author by

anaghapramesh

Updated on June 04, 2022

Comments

  • anaghapramesh
    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
      Bumsik Kim almost 5 years
      Use WebDriver or Puppeteer.
    • chickity china chinese chicken
      chickity china chinese chicken almost 5 years
      There's Sikuli too
  • Reedinationer
    Reedinationer almost 5 years
    I believe PyAutoGUI has a screenshot function too that should probably be included in your post!
  • Matt M
    Matt M almost 5 years
    I didn't include it originally since it really isn't Chrome's screenshot function. But I added it in
  • Reedinationer
    Reedinationer almost 5 years
    Yeah, 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 optional region argument though. I think between the two answers the problem should be easily solvable!