06-07-2021 05:07 AM - edited 06-07-2021 05:15 AM
Hi,
I'm having a problem controlling a website, namely I can submit forms with labview. In the code I have attached I use a free email provider (www.freemail.hu) as an example. If you navigate to this site you just find yourself on a login page and if you click on the blue button without entering any text to the textfields above:
you'll see that the page responds with red texts saying you need to enter a username / password.
In the page I need to control the scenario is pretty much the same. The problem though is it seems that I can't control the button. I have no problems controlling the text fields and also no problem finding the button itself, its just that I can't automate the click event.
Interestingly I have no problem automating the click event on the gray (register) button. That works without any issues and the browser in my labview VI redirects to the new page.
The other interesting thing I have found is that if pause my VI once the page is loaded I can press the register button manually and it works, but no matter if I press the blue button it does not reload the page so the red warnings don't appear.
Another thing is that if I use the chrome's developer tools and enter the following lines to the console:
x = document.getElementsByName("loginBtn")[0]
x.click()
then the page works fine.
Its really beyond my knowledge how the two buttons work differently however I'm calling the same method for both of them and if I just use native javascript than both works.
Any help would be appreciated. Thanks!
06-11-2021 12:55 PM - edited 06-11-2021 12:59 PM
Hi,
I've checked www.freemail.hu and they're using jQuery for HTTP POST request processing,
as javascript support for Web Browser included in System.Windows.Forms(4.0.0.0) is limited
it cannot process "submit" JavaScript event handled with jQuery.
In the page I need to control the scenario is pretty much the same. The problem though is it seems that I can't control the button. I have no problems controlling the text fields and also no problem finding the button itself, its just that I can't automate the click event.
if there's mobile version for that page it is worth trying, as plain HTTP POST should work as intended.
Its really beyond my knowledge how the two buttons work differently however I'm calling the same method for both of them and if I just use native javascript than both works.
Belépés - fires a "submit" JavaScript event which is later processed with jQuery
Regisztrálok - redirects to another URL
06-21-2021 08:57 AM
I have abandoned this project for couple days but today I made further research. I wrote a small VI which is capable to inject and then execute JS code to page.
I have injected and called the following function:
function whatever(){
alert("hello world");
document.getElementsByName("loginBtn")[0].click();
}
The injection works fine for sure cause, the "hello world" popup shows up. It doesnt click to the button though...
Also tried to call:
document.getElementsByName("loginBtn")[0].parentElement.parentElement.parentElement.submit()
which directly submits the form. Works from console not from labview
Interestingly the embedded browser doesnt respond even if I manually click to the button. This really suggests that something is wrong with the embedded browser, or it has some sort of a setting that I'm not aware of cause right now it seems that it can't submit a form properly no matter if I try to do it manually, from firing a click event, or from javascipt.
Again all these work fine from chrome.
06-21-2021 09:09 AM
most likely the embedded browser isn't processing external js.
try wrinting alert("hello world") in a seperate file and include it on your page, and see if it works(I think it won't work).
https://www.w3schools.com/tags/att_script_src.asp
06-22-2021 02:18 AM
I'm not an expert of the topic but what you said makes sense. In this case though I'm really wondering why the embedded browser is crippled? 😛