aisingapore / TagUI

Free RPA tool by AI Singapore
Apache License 2.0
5.59k stars 580 forks source link

1_google.tag fails to find element q - try this, google.com different for diff locations #944

Closed 42Network closed 3 years ago

42Network commented 3 years ago

Plain vanilla TagUI macOS install, per the instructions. Fails to find anything:

nathan@Nathans-MBP samples % tagui ./1_google.tag 

START - automation started - Tue Feb 23 2021 10:25:08 GMT-0600 (CST)

https://www.google.com - Google
type q as latest movies[enter]
click (//*[@class="g"])[1]//a
ERROR - cannot find (//*[@class="g"])[1]//a

Using Chrome TagUI plugin, I discover the search box is not named as "q" but as ".gLFyf.gsfi":

https://www.google.com/
type .gLFyf.gsfi as solar ecpipselipse[enter]

If I edit 1_google.tag to match the weird name, it works:

nathan@Nathans-MBP samples % tagui ./1a_google.tag 

START - automation started - Tue Feb 23 2021 12:19:49 GMT-0600 (CST)

https://www.google.com - Google
type .gLFyf.gsfi as latest movies[enter]
click (//*[@class="g"])[1]//a
wait 3
snap page to top_result.png

https://editorial.rottentomatoes.com/guide/the-best-movies-of-2020/ - The Best Movies of 2020 – Best New Films of the Year << Rotten Tomatoes – Movie and TV News
FINISH - automation finished - 11.5s

What is wrong here? Google page source:

`

`

It appears TagUI only looks for the "input class", and not the name? What am I doing wrong?

Thanks

ruthtxh commented 3 years ago

Hello @42Network

This sample flow should work on macOS too. I just tried running it on my macbook and it works.

Both name (q) and class (.gLFyf.gsfi) attributes should work. The chrome TagUI plugin just returns one of the many identifier which TagUI tries to detect. FYI, TagUI auto-selects provided identifier in this order - xpath, css, id, name, class, title, aria-label, text(), href.

I am suspecting the search results might have taken a while to return, perhaps due to a lag in network connectivity at that particular moment. Hence TagUI was unable to find the search results (cannot find (//*[@class="g"])[1]//a). You may also want to check if your chrome browser is up to date - if there's a pending update it should show on the top right corner of the browser with the word "Update".

kensoh commented 3 years ago

(oops, after posting then I saw Ruth's message, I didn't refresh the issue page from earlier)

Hi Nathan, thanks for raising this issue!

Adding on, the example is also working on my computer. This is because google.com renders differently base on user's location. TagUI smart identifier search actually checks through a few things for the best match. The exact order is xpath, css, id, name, class, title, aria-label, text(), href

More reference - https://github.com/kelaberetiv/TagUI/tree/pre_v6#steps-description

And it not just checks for an exact match, it checks if an element contains the string you provide too. For eg if you provide click cde and there is a button with some ID, name or attribute abcdefg it will also work and click on this. This is to handle situations where website has some minor change and break the automation, and also to make the code shorter if you wish.

Please try the following to see if it works on your computer. If it works, it's because there must be some other element with css, id or name that contains the string 'q' and it got matched before that element. Using below ensures that you are clicking on the element with name attribute "q"

type //*[@name="q"] as latest movies[enter]

PS - thanks Ruth!

42Network commented 3 years ago

Hi. Thanks for your suggestions.

My Chrome is at the latest version (Version 88.0.4324.192 (Official Build) (x86_64)). And unfortunately, changing the 1_google.tag to use [@name="q"] still didn't help.

This doesn't seem to be a performance issue either, because when I try "tagui live" and watch the Chrome window, TagUI never even tries to initiate the search. It just does nothing at all since it cannot seem to find the "q" field. Very baffling.

Are there any further troubleshooting steps? Mine is a very simple case. Vanilla TagUI install, using your basic sample, my location is USA. And clearly, based on the page source I posted, the field is still named "q" yet TagUI doesn't find it.

FYI I verified that PhantomJS is working with no permission issues and I am using the Amazon OpenJDK, as recommended.

I was very hopeful this TagUI package would work for me, but it is disappointing that a simple Google search fails. I'm feeling dumb here....

kensoh commented 3 years ago

Hi Nathan, thanks for sharing all these details!

This is indeed very puzzling. Can you run the script, and after it hangs or completes, drag and drop to attach a copy the log file tagui/src/tagui_chrome.log here, so that we can check what could have gone wrong there.

kensoh commented 3 years ago

Adding on, for us, when we try accessing the Google US page with below URL - https://www.google.com/?gl=us&hl=en&gws_rd=cr&pws=0

type q as 123 doesn't work because the Feeling Lucky button has an attribute containing the 'q' string, but type //*[@name="q"] as 123 works for us and it does type into the search box.

For reference, this is what we see on our tagui_chrome.log when doing type //*[@name="q"] --> matches with 1

[tagui] INPUT  -
[24] {"id":24,"method":"Runtime.evaluate","params":{"expression":"document.evaluate('//*[@name=\"q\"]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength"}}
[tagui] OUTPUT -
[24] {"id":24,"result":{"result":{"type":"number","value":1,"description":"1"}}}

[tagui] INPUT  -
[25] {"id":25,"method":"Runtime.evaluate","params":{"expression":"document.evaluate('//*[@name=\"q\"]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0).focus()"}}
[tagui] OUTPUT -
[25] {"id":25,"result":{"result":{"type":"undefined"}}}
42Network commented 3 years ago

Here is my latest log file. I think you are right about the "Feeling Lucky" button. I see it blink briefly when the script runs.

Thanks for looking into this!

tagui_chrome.log

42Network commented 3 years ago

Here is the log file using the @name="q" query. You can see there is an error saying:

"type":"object","subtype":"error","className":"DOMException","description":"DOMException: Failed to execute 'querySelectorAll' on 'Document': 'type //*[@name=\"q\"]' is not a valid selector.\n at <anonymous>:1:10"

So why would Chrome think that is an invalid selector?

tagui_chrome.log

kensoh commented 3 years ago

Something is going very wrong on your computer, notice that in the logs, the identifier includes the type word?

type //*[@name=\"q\"]

Checking more.

kensoh commented 3 years ago

But my log is just //*[@name=\"q\"]

kensoh commented 3 years ago
  1. Can you try downloading and use the steps here again? -https://tagui.readthedocs.io/en/latest/setup.html#macos-linux

  2. If error still happens, try downloading this zip https://github.com/kelaberetiv/TagUI/archive/master.zip and copy everything inside tagui/src folder to overwrite your installation in step 1

The kind of error above I can imagine only happens if somehow the TagUI source code has been modified or accidentally changed, in order to break it that way. In your log file, TagUI is not only sending the identifier over to Chrome, it is also sending the 'type ' string as part of the identifier to search for, so for sure it will break. But I can't think of any reason why your copy is behaving that way and have not seen anything like this situation before being reported.

42Network commented 3 years ago

Are TagUI and RPA for Python incompatible with each other? Originally I had installed RPA for python with "pip3 install rpa" and that put a bunch of stuff in a hidden .tagui directory. But since I couldn't get RPA for Python working quite right, I tried to uninstall it and then installed plain TagUI to see if it would work by itself, but obviously it isn't.

Can you tell me how to make sure both RPA for Python (.tagui) and TagUI are fully removed from macOS, so I can start clean with just TagUI?

Thanks

kensoh commented 3 years ago

TagUI and RPA for Python can exist together on the same computer. They each have their own installation directories. RPA for Python is based on a fork of TagUI optimised for the Python package, that's why it maintains its own directory. Yes for Mac it is a .tagui directory.

To delete RPA for Python, be very careful, just delete the .tagui directory. And pip3 uninstall rpa

To delete TagUI, you delete the tagui folder which you unzip, and remove that folder from your path environment variable.

kensoh commented 3 years ago

We have a weekly live Q&A where we meet users in Zoom breakout rooms to troubleshoot issues 1-to-1.

This is the details https://github.com/kelaberetiv/TagUI/issues/914 but I think it is bad timing for Texas (Thursday 2am your time)

42Network commented 3 years ago

False alarm! I made a mistake in my 1b_google.tag and actually had written

type type //*[@name="q"] as latest movies[enter]

When I removed the superfluous type, it works!

nathan@Nathans-MacBook-Pro samples % tagui ./1b_google.tag

START - automation started - Thu Feb 25 2021 22:32:55 GMT-0600 (CST)

https://www.google.com - Google
type //*[@name="q"] as latest movies[enter]
click (//*[@class="g"])[1]//a
wait 3
snap page to top_result.png

https://www.vulture.com/article/best-movies-on-netflix-right-now.html - 100 Best Movies on Netflix Right Now (February 2021)
FINISH - automation finished - 10.6s

So what is the lesson to be learned here? Your 1_google.tag sample didn't work out of the box but needed to be targeted to look for name=q. How can we catch this kind of gotcha in the future? Can you put a note in the tutorials about this possibility?

Now on to my actual use case, which is to automatically download my recent bank transactions on a daily basis.

Thanks!

kensoh commented 3 years ago

Thanks Nathan for your feedback! I've updated the Google example in samples.

I added an additional line and note as fallback due to difference in google.com for different locations.

// This flow makes a search on Google, clicks the first result and screenshots the page

// First, visit google.com
https://www.google.com

// Look on the web page for an element with 'q' in its text, id or name
// (or some other attributes), then type 'latest movies' and enter
type q as latest movies[enter]

// Use below if above fails, google.com differs for different locations
// type //*[@name="q"] as latest movies[enter]

// Click the first result using XPath
// Learn XPath: https://www.w3schools.com/xml/xpath_intro.asp
click (//*[@class="g"])[1]//a

// Wait 3 seconds so the page can load
wait 3

// Save a screenshot of the web page to top_result.png
snap page to top_result.png
42Network commented 3 years ago

Thanks for your help kensoh