RPA-Python icon indicating copy to clipboard operation
RPA-Python copied to clipboard

frame() does not work properly when crossing domain

Open yucongshub opened this issue 1 year ago • 0 comments

Hello, Before asking the question, I have seen similar questions, such as: https://github.com/tebelorg/RPA-Python/issues/476 , but it does not have a good test and a result, so I want to reopen an issue to see if I can push the solution to the frame() problem.

When I used frame() to switch to iframe, it returned True, but I could not retrieve any elements in this iframe normally, such as using present() or read(), so I did some tests and got some maybe useful information

image image chrome engine error message: [tagui] INPUT - [17] {"id":17,"method":"Runtime.evaluate","params":{"expression":"document.evaluate('//img',mainframe_context,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotLength"}} [tagui] OUTPUT - [17] {"id":17,"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":"6975999204845677721.3.3"},"exceptionDetails":{"exceptionId":206,"text":"Uncaught","lineNumber":0,"columnNumber":9,"scriptId":"719","stackTrace":{"callFrames":[{"functionName":"","scriptId":"719","url":"","lineNumber":0,"columnNumber":9}]},"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":"6975999204845677721.3.4"}}}}

I switched frame() again so that I could get the switching process from the beginning, and then did some tests in the chrome console. The results are as follows: [tagui] INPUT - [22] {"id":22,"method":"Runtime.evaluate","params":{"expression":"mainframe_context = document.evaluate('(//frame|//iframe)[@name=\"hahahaha\" or @id=\"hahahaha\"]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0).contentDocument"}} [tagui] OUTPUT - [22] {"id":22,"result":{"result":{"type":"object","subtype":"null","value":null}}}

image You can see that the content of the iframe cannot be obtained using contentDocument.

image If you change it to contentWindow, it can be obtained, but if you use contentWindow.document, you will be prompted for cross-domain.

PS. When testing frame() in another non-cross-domain environment, it is normal to use contentDocument. image


So other than using visual automation, can this problem be solved from the frame() side?

In addition, I also did some selenium tests, which can solve this problem through driver.switch_to.frame(), but my coding ability is limited and I cannot refer to selenium's methods to improve Tagui.

yucongshub avatar Feb 01 '24 03:02 yucongshub