RPA-Python
RPA-Python copied to clipboard
dom() sometimes does not execute and sometimes does not return a value
this is my code
# step 1. print log
commons.Logging('execute js')
# step 2. execute js and print element value
commons.Logging(r.dom("return document.querySelector('.titleText').outerHTML"))
# step 3. print variable
commons.Logging(commons.config_data['setelesvalue'])
# step 4. execute js
r.dom(commons.config_data['setelesvalue'])
# step 5. wait 10000s
r.wait(10000)
this is print logs
2024-06-27 10:23:25,893 - commons.py[line:54] - INFO: execute js
2024-06-27 10:23:25,906 - commons.py[line:54] - INFO:
2024-06-27 10:23:25,906 - commons.py[line:54] - INFO: let eles = document.querySelectorAll('.el-input__inner, .el-textarea__inner'); for (let i = 0; i < eles.length; i++) { eles[i].setAttribute('value', eles[i].value); }
We can see that step 2 does not print a return value
this is tagui log 'tagui_chrome.log'
[tagui] INPUT -
[182] {"id":182,"method":"Target.sendMessageToTarget","params":{"sessionId":"21196D323E39AA784EB990866AA99E57","message":"{\"id\":182,\"method\":\"Input.dispatchMouseEvent\",\"params\":{\"type\":\"mouseMoved\",\"x\":228,\"y\":267,\"button\":\"none\",\"clickCount\":0}}"}}
[tagui] OUTPUT -
[182] {"method":"Target.receivedMessageFromTarget","params":{"sessionId":"21196D323E39AA784EB990866AA99E57","message":"{\"id\":182,\"result\":{}}","targetId":"B2C3C53244B1D6BB20308409693F2569"}}
[tagui] INPUT -
[183] {"id":183,"method":"Target.sendMessageToTarget","params":{"sessionId":"21196D323E39AA784EB990866AA99E57","message":"{\"id\":183,\"method\":\"Input.dispatchMouseEvent\",\"params\":{\"type\":\"mousePressed\",\"x\":228,\"y\":267,\"button\":\"left\",\"clickCount\":1}}"}}
[tagui] OUTPUT -
[183] {"method":"Target.receivedMessageFromTarget","params":{"sessionId":"21196D323E39AA784EB990866AA99E57","message":"{\"id\":183,\"result\":{}}","targetId":"B2C3C53244B1D6BB20308409693F2569"}}
[tagui] INPUT -
[184] {"id":184,"method":"Target.sendMessageToTarget","params":{"sessionId":"21196D323E39AA784EB990866AA99E57","message":"{\"id\":184,\"method\":\"Input.dispatchMouseEvent\",\"params\":{\"type\":\"mouseReleased\",\"x\":228,\"y\":267,\"button\":\"left\",\"clickCount\":1}}"}}
[tagui] OUTPUT -
[184] {"method":"Target.receivedMessageFromTarget","params":{"sessionId":"21196D323E39AA784EB990866AA99E57","message":"{\"id\":184,\"result\":{}}","targetId":"B2C3C53244B1D6BB20308409693F2569"}}
[tagui] INPUT -
[185] {"id":185,"method":"Target.sendMessageToTarget","params":{"sessionId":"21196D323E39AA784EB990866AA99E57","message":"{\"id\":185,\"method\":\"Runtime.evaluate\",\"params\":{\"expression\":\"(function (dom_json) {return document.querySelector('.titleText').outerHTML;})({})\"}}"}}
[tagui] OUTPUT -
[185] {"method":"Target.receivedMessageFromTarget","params":{"sessionId":"21196D323E39AA784EB990866AA99E57","message":"{\"id\":185,\"result\":{\"result\":{\"type\":\"string\",\"value\":\"<span class=\\\"titleText\\\">\\u4fe1\\u8bbf\\u4eba\\u4fe1\\u606f</span>\"}}}","targetId":"B2C3C53244B1D6BB20308409693F2569"}}
We can see that 182~184 are click element operations, which is correct. 185 is the DOM operation of executing js, which returns the value here, but it is not printed in the code. This is the first problem. The second problem is that the log ends here. which may be the code where r.wait(10000) is executed, but the other js step4 r.dom(commons.config_data['setelesvalue'])
does not have a log to prove that it has been executed.