tebelorg / RPA-Python

Python package for doing RPA
Apache License 2.0
4.95k stars 669 forks source link

[RPA][ERROR] - cannot find XPath - use frame() in this case to specify frame #243

Closed linolc closed 3 years ago

linolc commented 3 years ago

I'm trying to enter text in the 'placa' field, but RPA doesn't find XPath. I've tried by ID, Name, among others. The same problem occurs for the other fields and buttons on the page.

import pyautogui as p
import rpa as r

r.init()
r.url('https://www.meudetran.ms.gov.br/veiculo.php#')
p.sleep(2)
r.type('//*[@id="id_sc_field_placa"]', 'Teste')

[RPA][ERROR] - cannot find //*[@id="id_sc_field_placa"]

kensoh commented 3 years ago

Hi @LinoLuiz you can try the following -

import rpa as r

r.init()
r.url('https://www.meudetran.ms.gov.br/veiculo.php#')
r.frame('ifrm-pdr-portal')
r.type('sc_clone_placa', 'Teste')
...

The web page uses frames, you can check by searching in Inspector (below image). So there is a need to use frame() to tell the tool that you are looking for elements in that frame and not elsewhere. A web frame is a separate web page / HTML doc.

Screenshot 2021-05-04 at 3 01 04 AM

Also, the input field seems to have duplicates (same id happening twice). You can either append [2] at the end to mean the 2nd match, or use what I did by providing the name attribute which directly points to the correct element.

Screenshot 2021-05-04 at 2 57 21 AM

Lastly, there is no need to wait explicitly, the tool will auto-wait up to timeout of 10 seconds before throwing error.

Even if you need to wait, you can use r.wait() and do not need to import another package like pyautogui to do that.

linolc commented 3 years ago

Thank you so much for your help @kensoh! I researched a lot and found no solution.