longvh211 / Chromium-Automation-with-CDP-for-VBA

A method to directly automate Chromium-based web browsers, such as Chrome, Edge, and Firefox, using VBA for Office applications by following the Chrome DevTools Protocol framework.
MIT License
45 stars 6 forks source link

element.value and fireEvent still won't work in VUE or React #29

Closed wolfccb closed 2 months ago

wolfccb commented 3 months ago

Thank you very much for this great project! I am working with a VUE (or React, or both, not sure) login form in Chrome, and tried the following code in VBA:

Set userName=chrome.getElementsByQuery("input[class='el-inputinner']")(1) Set passWord=chrome.getElementsByQuery("input[class='el-inputinner']")(2) Set btnLogin=chrome.getElementsByQuery("button[type='button']")(1) userName.value="testuser" userName.fireEvent ("input") passWord.value="password" passWord.fireEvent ("input") btnLogin.click

I can see from the Chrome page that the values have been correctly shown in the form, and the InputEvents have been successfully triggered (which behave just like I dispatch the events in Chrome console). The btnLogin.click works, too.

But the webpage still tells me that both userName and passWord are empty. This can be solved by clicking the values in the input boxes. I tried some methods in console such as userName.focus(), .click(), or dispatch several events, the problem still exists.

I know that you have made a Sendkeys method, but unfortunately I have to make my VBA run with Task scheduler, which means it is hidden.

Is there a way to simulate user input?

Thank you and good luck!

longvh211 commented 3 months ago

Hi there, thanks for the comment. Are you able to reproduce the problem somewhere that I can test on? And how come you are unable to use the SendKeys method with running VBA from Task Scheduler?

wolfccb commented 3 months ago

Thanks for the quick reply. I am afraid I am not able to put it online because it's an intranet website. As for task scheduler, if we want it to run a task even when user is not logged in Windows, we have to tell Windows password to it, and it will run the task invisibly. There seems no option on this behavior. I searched a lot during the past days and tried in Chrome console, but I still cannot login the website in automated way, not even in console. Any suggestion is appreciated. Thanks again!

在 2024年8月5日,23:05,Long Vh @.***> 写道:



Hi there, thanks for the comment. Are you able to reproduce the problem somewhere that I can test on? And how come you are unable to use the SendKeys method with running VBA from Task Scheduler?

— Reply to this email directly, view it on GitHubhttps://github.com/longvh211/Chromium-Automation-with-CDP-for-VBA/issues/29#issuecomment-2269298903, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANGPANVGOWEZLGC4EAUHNRTZP6IFFAVCNFSM6AAAAABMAPGTASVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRZGI4TQOJQGM. You are receiving this because you authored the thread.Message ID: @.***>

MitsOmitsaras commented 3 months ago

I am not an expert, but have you tried to set the innerText property instead of value? Sometimes this works for me.

longvh211 commented 3 months ago

It is hard for me to help you since the issue is not recreatable for me to test. Anyway at best I can only suggest the followings:

wolfccb commented 3 months ago

Thanks @longvh211 @MitsOmitsaras . Problem solved. Here it is:

Set userName=chrome.getElementsByQuery("input[class='el-inputinner']")(1) Set passWord=chrome.getElementsByQuery("input[class='el-inputinner']")(2) Set btnLogin=chrome.getElementsByQuery("button[type='button']")(1) userName.value="testuser" userName.fireEvent ("focus") userName.fireEvent ("input") userName.fireEvent ("change") userName.fireEvent ("blur") passWord.value="password" passWord.fireEvent ("focus") passWord.fireEvent ("input") passWord.fireEvent ("change") passWord.fireEvent ("blur") btnLogin.click

It seems this website requires such series of event to validate user input. Maybe it's a good idea to add some notes to the project demo.

Good luck!

longvh211 commented 2 months ago

Thanks a lot for the update buddy. It is unusual to require that many events for just a single input field. Usually only one among those should be enough (such as "change" or "blur") I think.