tebelorg / RPA-Python

Python package for doing RPA
Apache License 2.0
4.87k stars 663 forks source link

Click on button not running - user tried clicking twice to make it work #138

Closed ongkokl closed 4 years ago

ongkokl commented 4 years ago

Hi @kensoh

Last question for the evening , my first Python RPA mini project is almost done :)

Why the r.click('//*[@class = "report-inventory__search-button-label"]') seem doesnt running ? While i testing it with remove the r.clicks on above, it does run.

`

r.click('//*[@class = "mat-select-arrow"]')

r.click('mat-option-0')

r.click('mat-option-1')

r.click('mat-option-5')

r.click('mat-option-6')

*r.click('//[@class = "report-inventory__search-button-label"]')** `

kensoh commented 4 years ago

If something cannot be found, it will timeout after 10 seconds and show error message. For Class attribute, normally we write as @class lowercase. One way to test something is run in Python interactive mode (type python command from command prompt), or use Jupyter notebook.

That way, you can test each step to see what's working and why not working. Also, if you do r.debug(True) you will get log and output to screen all the automation in the background, that can help see where the problem too.

ongkokl commented 4 years ago

If something cannot be found, it will timeout after 10 seconds and show error message. For Class attribute, normally we write as @class lowercase. One way to test something is run in Python interactive mode (type python command from command prompt), or use Jupyter notebook.

That way, you can test each step to see what's working and why not working. Also, if you do r.debug(True) you will get log and output to screen all the automation in the background, that can help see where the problem too.

Hi @kensoh

Thanks , I managed to figure out .

I saw the video on the redmart use case to send outlook mail. Do I need to import other library for it ?

kensoh commented 4 years ago

I don't think there is a video on RedMart and Outlook. For RedMart, it is normal web automation. For sending email using Gmail or MS Outlook, you can try using the visual automation method - https://github.com/tebelorg/RPA-Python#visual-automationsee_no_evil and keyboard automation https://github.com/tebelorg/RPA-Python#keyboard-automationmusical_keyboard

Here is an example combining DBS website and Gmail sending. It is for TagUI, but from there you can get an idea the syntax for RPA for Python.

https://github.com/aimakerspace/TagUI-Bricks/tree/master/DBS-Forex-Gmail

kensoh commented 4 years ago

No need to import any other library.

ongkokl commented 4 years ago

@kensoh

I thought I had solved the issue but the click button still not working.

[RPA][28] - exist_result = exist('report-inventorysearch-button-label').toString() [RPA][28] - listening for inputs [RPA][29] - dump exist_result to rpa_python.txt [RPA][29] - listening for inputs [RPA][30] - click report-inventorysearch-button-label [RPA][30] - listening for inputs <function tagui.close()>

`r.click('//*[@class = "mat-select-arrow"]') r.click('mat-option-0') r.click('mat-option-1') r.click('mat-option-5') r.click('mat-option-6')

r.debug(True) r.click('report-inventory__search-button-label') r.close`

This how how i do to resolve this issue, run the code 2 times.

r.click('report-inventory__search-button-label') r.click('report-inventory__search-button-label')

kensoh commented 4 years ago

Thanks for sharing your solution!

Interesting web element that needs to click twice to work. I assume you are saying for normal human user click once works but for automation need to click twice. The visual automation method could also be handy as it replicates the human user click instead of simulating the click within Chrome browser. Just need to make sure that Chrome browser is in focus first (eg doing a click visually on the Chrome icon on taskbar).

kensoh commented 4 years ago

Closing the issue for now till further inputs

LucieGattepailleQB commented 6 months ago

I experienced the same issue, and the fix above works. In my case, the first r.click(element) got the view of the page to move to the element and the second r.click(element) got it to be clicked like I wanted. Thanks a lot for finding a fix!

kensoh commented 1 month ago

Normally it should just work, my best guess is it might be a slow or heavy page, so it hasn't completed the scrolling up when the click event happens. And the 2nd click will hit because the scroll already happened.

By design, click() will scroll to the web element first, before clicking it.