RPA-Python: r.frame methods fail when inside iframe - Chrome not returning a match for this use case
Dear author, I have found that the r.frame method fails when url is inside the iframe, and I hope you can help fix this problem. Here is an case:
import rpa as r
if __name__ == '__main__':
r.init(visual_automation=True, chrome_browser=True)
r.url('http://localhost:63342/RPA-Python/iframe.html?_ijt=t9p2cu8m44uie9u1cb2bdfa1d2&_ij_reload=RELOAD_ON_SAVE')
# r.url('http://www.tagui.com.cn/')
r.dom('document.evaluate(\'/html/body/iframe\', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).setAttribute("name", "iframe-test")')
r.frame('iframe-test')
r.wait(5)
r.click('/html/body/div[1]/nav/div/div[2]/ul/li[1]/a')
r.wait(30)
r.close()
I want to click the menu in ‘http://www.tagui.com.cn/’ when the url is inside the iframe, but there is an error ‘[RPA][ERROR] - cannot find /html/body/div[1]/nav/div/div[2]/ul/li[1]/a’.
The content of iframe.html is as below:
<iframe src='http://www.tagui.com.cn/' style='width: 100%;height: 100%;'>
</iframe>
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 19 (8 by maintainers)
thinks, mybe I can only visit the url of iframe directly.
At 2024-01-07 10:30:39, “Ken Soh” @.***> wrote:
Adding on to above 2 debugging findings,
I found this post - https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome
When I add below to the tagui script to disable web security and enable the cross-site stuffs,
chrome_started=“$(uname -s)”; chrome_switches=“–disable-web-security --disable-features=IsolateOrigins,site-per-process --remote-debugging-port=9222 about:blank”
Chrome is still returning nothing when tried to query the element in the frame, when the frame object is valid -
[109] {“id”:109,“result”:{“result”:{“type”:“object”,“subtype”:“error”,“className”:“TypeError”,“description”:“TypeError: Failed to execute ‘evaluate’ on ‘Document’: parameter 2 is not of type ‘Node’.\n at <anonymous>:1:10”,“objectId”:“2030281531867037696.3.95”},“exceptionDetails”:{“exceptionId”:48,“text”:“Uncaught”,“lineNumber”:0,“columnNumber”:9,“scriptId”:“13”,“exception”:{“type”:“object”,“subtype”:“error”,“className”:“TypeError”,“description”:“TypeError: Failed to execute ‘evaluate’ on ‘Document’: parameter 2 is not of type ‘Node’.\n at <anonymous>:1:10”,“objectId”:“2030281531867037696.3.96”}}}}
I cannot assist further, because if you trace above, Chrome literally is just not turning a match when querying a valid frame object with the following JavaScript code, even with the special flags enabled to launch Chrome.
mainframe_context = @.***=“iframe-test”]‘,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0) document.evaluate(’/html/body/div[1]/nav/div/div[2]/ul/li[1]/a’,mainframe_context,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength
My suggestion is if you can query the URL of the frame directly, instead of accessing it as a frame. There is something around Chrome’s behaviour which I suspect is related to cross-site security, but this edge case is not something the rpa package can change or support. cc @RichiardChi
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>