0

I'm learning how to do RPA, and a lot of what I want to accomplish involves manipulating checkboxes and text fields on Chrome. I'm trying to find a way to either:

  1. Return a list of all elements of a specific type in Chrome (For example, all the element IDs of checkboxes, buttons, or text fields).

or

  1. Have a user click on an element or use a hot key while hovering over an element to get the element ID.

The idea is that if I can have the element to manipulate selected by the user while the program is running, I can automate tasks more efficiently without having to change the parameters by manually inspecting the element in Chrome and changing the code.

Basically I'm trying to create a crude element selector in Python, or to just display a list of elements so the user can choose which element to interact with.

Currently I'm attempting to find the syntax to return all elements in the active window using pywinauto, and am exploring the use of Beautiful Soup to parse the HTML. However I assume there must be a simple one or two line code to do this, so if possible I would like to learn how to do it correctly rather than hack together a crude function that accomplishes it ineffectively.

CrazyChucky
  • 3,263
  • 4
  • 11
  • 25
  • I need to be able to find it through Python at runtime because every time the program is run, different elements will be needed. I need to be able to retrieve the element ID at a specific position when the program is being run. –  Dec 19 '20 at 03:02
  • Can you provide more context, or perhaps an example? It's unclear, at least to me, what you're trying to do. Is Python running a local server you're accessing via Chrome? Are you running Python on your computer and trying to access the Chrome app from it? Is it something else? – CrazyChucky Dec 19 '20 at 03:22
  • 1
    I'm attempting basically to create a crude element selector in Python. I need to be able to have the user click or hover over an element, and to then be able to return the element id that's selected. It's for RPA, my intention is to define the element in the script itself so I can evaluate whether or not to click on or otherwise manipulate the element. I'm able to accomplish this in AutoHotKey but am trying to learn Python as I was told it would offer more functionality. I've been trying to find a solution to this all day though so maybe Python isn't the right way to do this at all? –  Dec 19 '20 at 03:28
  • @TheNomadicAspie don’t just copy your description. You should answer CrazyChucky ‘s question – mehtaarn000 Dec 19 '20 at 03:32
  • 1
    I did the opposite, I updated my original question because I was told it was unclear the way it was worded. –  Dec 19 '20 at 03:36
  • Thanks, that helps some. So, to be clear, you're NOT making the web site, or whatever content Chrome is viewing. You want Python to observe what the user clicks or hovers in Chrome, and... you also want to be able to send click or other events to Chrome from Python? – CrazyChucky Dec 19 '20 at 03:45
  • Yes. Well ideally I would like to be able to get an element from any window, not just Chrome. But with other programming languages I've had obstacles doing this with Chrome specifically because unless the accessibility flag is run, Chrome tends to not return element IDs. But I'm simply trying to find ANY way to get a selected element ID in Python. I would even be happy if I could get a list of all elements in the active window. I believe pywinauto has a way to do it but I've read the entire documentation and it's unclear to me how. I'm sorry, I'm very new to Python and am used to C#. –  Dec 19 '20 at 03:49
  • Primarily HTML elements in Chrome but I would like to learn how to manipulate both checkboxes in Chrome as well as other programs. I'm trying to learn about RPA as a career, so this is mostly me trying to figure out how to work with elements and UI components in general. I'm two days into learning Python and have only put together 18 lines of code after reading most of the documentation of pywinauto, pyautogui, and RPA. Most of what I'm trying to accomplish requires the user to first target an element to be manipulated either in Chrome or another program. –  Dec 19 '20 at 04:01
  • So my workflow is to have the user select the active window, retrieve the hwnd (Which I've already done), select an element/control/button on the window, and evaluate whether or not to manipulate it. And eventually I will need to be able to do that with Chrome, other browsers, as well as desktop applications. I just can't seem to find a way to find an element without searching for it based on predefined parameters. Is it just a matter of looking for the name and using * to return all of them? –  Dec 19 '20 at 04:04
  • At this point I don't even care if I retrieve it through clicking on it, or just if I can return a list of all the controls/buttons/elements on a page to further evaluate. –  Dec 19 '20 at 04:05
  • If I were you, I'd edit the question to clarify what you're doing, that you're doing it on Windows, that you're probably going to do it in pywinauto, and include an example of the code that you have tried, along with what incorrect results you're getting. – CrazyChucky Dec 19 '20 at 04:14
  • Thank you, I updated my original post. –  Dec 19 '20 at 04:20

0 Answers0