When you use Chrome or Chromium as a browser there is a much easier and much more stable approach using ONLY pyautogui:

  1. Perform Crtl + F with pyautogui

  2. Perform Ctrl + Enter to 'click' on search result / open the link related to the result

With other browsers you have to clarify if there keyboard shortcuts also exists.

Answer from Ulrich on Stack Overflow
🌐
GitHub
github.com › asweigart › pyautogui › issues › 521
Screenshot functions and "find text on screen in a dialog box" · Issue #521 · asweigart/pyautogui
January 7, 2021 - Question: How would it be possible to locate a UI element on screen via text and not via an image? This is a generalization of #520. ... Use WinAPI to get the actual text content of a dialog box, and find the position of each text element · Render the text with the default Windows GUI font (Segoe UI?) to a search.png file, and then use pyautogui.locateOnScreen('search.png') ?
Author   josephernest
Discussions

Read words using pyautogui, open-cv python and pytesseract
See the Quickstart on pytesseract project page (scroll down to 'Support for OpenCV image/NumPy array objects'): https://pypi.org/project/pytesseract/ Note: per documentation, you must convert your OpenCV image to RGB format (see link above) img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR) text = pytesseract.image_to_string(img) #Test the text # print(text) More on reddit.com
🌐 r/learnpython
2
0
October 11, 2021
Trying to use pyautogui and locateOnScreen
First, for automating web browsers you would probably be a lot better off with selenium, especially if you know a little html. Python gave me a syntax error when I used the full path for the image That's probably because you didn't use a raw string. Remember you always need to use raw strings for windows filepaths: pyautogui.locateOnScreen(r'C:\path\to\image\folder\Show Explanation.png') locateOnScreen returns the coordinates that it found. You need to save those coordinates and pass them to on click. Otherwise, click does not know where to click. coords = pyautogui.locateOnScreen('Show Explanation.png') pyautogui.click(coords) The returned coordinates will be None if the image is not found. So you probably want to add a check: coords = pyautogui.locateOnScreen('Show Explanation.png') if coords is None: print('Image not found on the screen!') else: pyautogui.click(coords) You'll probably also want to add a pause in a few places with time.sleep so that your computer has time to process the click / load the print dialog / etc. More on reddit.com
🌐 r/learnpython
7
4
August 17, 2017
pyautogui - Reading the text on screen using python - Stack Overflow
How do I get the text from a text file and save it as a variable in python? I tried saving it as an image and then using the pytesseract.image_to_string() but it did not seem to work More on stackoverflow.com
🌐 stackoverflow.com
pyautogui locate on screen returns a wrong coordinates
Looks like all of the indentations are lost in the post, so here’s a screenshot of that piece of code: https://ibb.co/4FyVmcD More on reddit.com
🌐 r/learnpython
7
3
September 26, 2021
🌐
PyAutoGUI
pyautogui.readthedocs.io › en › latest › quickstart.html
Cheat Sheet — PyAutoGUI documentation - Read the Docs
>>> pyautogui.alert('This displays some text with an OK button.') >>> pyautogui.confirm('This displays text and has an OK and Cancel button.') 'OK' >>> pyautogui.prompt('This lets the user type in a string and press OK.') 'This is what I typed in.' The prompt() function will return None if the user clicked Cancel. PyAutoGUI uses Pillow/PIL for its image-related data. On Linux, you must run sudo apt-get install scrot to use the screenshot features.
🌐
YouTube
youtube.com › coding 101 with steve
PyAutoGUI - Locate anything on your screen | Simple Pyautogui project - YouTube
This is the second tutorial video on PyAutoGUI. In this tutorial I will teach you to locate anything on your screen using locateCenterOnScreen() metod which ...
Published   March 3, 2022
🌐
Medium
medium.com › @rakesh.sheshadri44 › how-to-capture-a-screenshot-extract-text-with-ocr-clean-it-using-gpt-3-5-231e0cbfafef
How to Capture a Screenshot, Extract Text with OCR, Clean It Using GPT-3.5, and Automate Actions with PyAutoGUI | by Rakesh Sheshadri | Medium
January 15, 2025 - Capture Screenshot: Use PyAutoGUI to capture the screen. OCR Extraction: Use Tesseract to extract text from the image. Text Refinement: Use GPT-3.5 to clean and refine the text. Automation: Optionally, use PyAutoGUI to automate actions based on the cleaned text.
🌐
Python Forum
python-forum.io › thread-32327.html
how to take a screnshot by Pyautogui automatically and randomly
February 3, 2021 - objective i want to extract text from image. i play a game which an icon appears randomly ,and there is a text(text as image) near to the icon from the right. i want the script take screenshot of the region of the text only. so, i want the script eve...
Find elsewhere
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 2e › chapter20
20 controlling the keyboard and mouse with gui automation
You can use PyAutoGUI to obtain the window for a text editor such as Mu or Notepad, bring it to the front of the screen by clicking on it, click inside the text field, and then send the CTRL-A or -A hotkey to “select all” and CTRL-C or -C hotkey to “copy to clipboard.” Your Python script ...
🌐
YouTube
youtube.com › watch
python find text on screen - YouTube
Download this code from https://codegive.com Certainly! Detecting text on the screen can be achieved using Optical Character Recognition (OCR) libraries in P...
Published   December 11, 2023
🌐
PyAutoGUI
pyautogui.readthedocs.io › en › latest › screenshot.html
Screenshot Functions — PyAutoGUI documentation
>>> import pyautogui >>> im = pyautogui.screenshot(region=(0,0, 300, 400)) NOTE: As of version 0.9.41, if the locate functions can’t find the provided image, they’ll raise ImageNotFoundException instead of returning None. You can visually locate something on the screen if you have an image file of it.
🌐
ProgramCreek
programcreek.com › python › example › 103347 › pyautogui.locateOnScreen
Python Examples of pyautogui.locateOnScreen
pyautogui.useImageNotFoundException(False) self.assertEqual(pyautogui.locate("100x100blueimage.png", "100x100redimage.png"), None) # self.assertEqual(pyautogui.locateAll('100x100blueimage.png', '100x100redimage.png'), None) # self.assertEqual(pyautogui.locateAllOnScreen('100x100blueimage.png'), None) # NOTE: This test fails if there is a blue square visible on the screen.
🌐
CodePal
codepal.ai › code-generator › query › CCACYmPG › python-find-and-click-text
Python Find and Click Text with pyautogui - CodePal
The function takes two parameters: ... accomplish this task, the function utilizes the locateOnScreen function from the pyautogui library to search for the target and click texts on the screen....
🌐
Read the Docs
app.readthedocs.org › projects › pyautogui › downloads › pdf › latest pdf
PyAutoGUI Documentation Al Sweigart Sep 14, 2021
September 14, 2021 - Returns the text of the button clicked on. ... Displays a message box with OK and Cancel buttons. Number and text of buttons can be customized. Returns the text ... Displays a message box with text input, and OK & Cancel buttons. Returns the text entered, or None if Cancel was ... Displays a message box with text input, and OK & Cancel buttons. Typed characters appear as *. Returns the text ... PyAutoGUI can take screenshots, save them to files, and locate images within the screen.
🌐
Reddit
reddit.com › r/learnpython › trying to use pyautogui and locateonscreen
r/learnpython on Reddit: Trying to use pyautogui and locateOnScreen
August 17, 2017 -

So, I am VERY new to Python and programming in general and have been researching how to make my program work for the past couple hours.

I am trying to create a program that will automate a repetitive task by clicking particular buttons for me on a particular internet site and printing (to a printer) what shows up when those buttons are pressed.

These buttons do not have the same coordinates on the screen each time, so I am trying to combine a click command with a locateOnScreen command. The program is running from the same directory as the screencaps I took for locateOnScreen - Python gave me a syntax error when I used the full path for the image, so I just used the file name.

When I run the program from IDLE, it will actually try to use that last command and print to the printer - if I confirm, it will simply print the ensuing shell message that pops up -

Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================ RESTART: C:\Users\***\Desktop\program.py ================ >>> 

Here is my program's code:

#!\C:\Users\***\AppData\Local\Programs\Python\Python36-32\
import pyautogui
pyautogui.PAUSE = 1
pyautogui.FAILSAFE = True
pyautogui.locateOnScreen('Show Explanation.png')
pyautogui.click
pyautogui.hotkey('ctrl', 'p')
pyautogui.locateOnScreen('Next.png')
pyautogui.click

It seems to me that I either messed up semantically and/or locateOnScreen is not working and trying to find the buttons in the shell window rather than the internet window that is right behind it (which is weird because I made sure the buttons are visible when I run it). I'm sure my code probably has at least one dumb error in it though...

🌐
Read the Docs
pyautogui.readthedocs.io
Welcome to PyAutoGUI’s documentation! — PyAutoGUI documentation
The source code is available on: https://github.com/asweigart/pyautogui ... Moving the mouse and clicking in the windows of other applications. Sending keystrokes to applications (for example, to fill out forms). Take screenshots, and given an image (for example, of a button or checkbox), and find it on the screen.
🌐
YouTube
youtube.com › codemore
python find coordinates of text on screen - YouTube
Download this code from https://codegive.com Certainly! To find the coordinates of text on the screen using Python, you can utilize the pyautogui library for...
Published   December 11, 2023
Views   701
🌐
Stack Overflow
stackoverflow.com › questions › 65662539 › reading-the-text-on-screen-using-python
pyautogui - Reading the text on screen using python - Stack Overflow
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import json # create empty dictionary variables_dict = {} # reads your textfile.txt and stores as 'textfile.txt' inside the dictionary with open("textfile.txt","r") as textfile: variables_dict["text.file.txt"]= textfile.read() print('\nvariables_dict : ',variables_dict) textfile.close() #save the dictionary as a json file 'variables.json' with open('variables.json', 'w') as variablessaved: json.dump(variables_dict, variablessaved) #read the dictionary as a json file 'variables.json' with open('variables.json', 'r') as variablesloaded: loaded_dict = json.load(variablesloaded) print('\nloaded dictionary : ' , loaded_dict) Again I am not sure about what you were looking for. ... Find the answer to your question by asking.
🌐
Quora
quora.com › How-can-I-write-a-script-that-will-read-the-screen-and-control-the-mouse-in-Python-Im-using-Windows-XP
How can I write a script that will read the screen and control the mouse in Python? I'm using Windows XP.
Answer (1 of 2): From your question, I guess the obvious answer would be PyAutoGUI, the best Python library for GUI automation. It’s still under development and has got a lot of planned features to coming up in their next versions. But it won’t read the screen and control the mouse, instead you n...
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 1e › chapter18
Controlling the Keyboard and Mouse with GUI Automation
You can even give PyAutoGUI a screen-shot and let it figure out the coordinates of the area you want to click. You can combine all of these PyAutoGUI features to automate any mindlessly repetitive task on your computer. In fact, it can be downright hypnotic to watch the mouse cursor move on its own and see text appear on the screen automatically.