Welcome Guest Search | Active Topics | Sign In | Register

why the JS can't be effective Options
sexfio
Posted: Wednesday, July 8, 2020 9:04:26 AM
Rank: Member
Groups: Member

Joined: 3/21/2020
Posts: 12
Code: Visual Basic.NET
dim js as string = "document.querySelector(""#fm-login-id"").value=""username"";document.querySelector(""#fm-login-password"").value=""userpass"";document.querySelector(""button[type=submit]"").click();"

WebView1.LoadUrl("https://pub.alimama.com/promo/search/index.htm?spm=a219t.11816994.1998910419.dd412374a2.6d3575a5TCfvnA")
WebView1.EvalScript(js)


I want use the JS to Login the page
if I use the JS in chrome's console >> yes,it is effective
but when I use the same JS in webview >> can't ,webview show the error msg " line 1, col 44 - 45: Uncaught TypeError: Cannot set property 'value' of null"

What causes this??
THX :)
eo_support
Posted: Wednesday, July 8, 2020 1:30:29 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

You are calling EvalScript too soon. LoadUrl starts loading the page and returns immediately. So by the time you call EvalScript the page has not finished loading yet. You can try to change LoadUrl to LoadUrlAndWait and see if it works for you.

Thanks!
sexfio
Posted: Wednesday, July 8, 2020 11:14:34 PM
Rank: Member
Groups: Member

Joined: 3/21/2020
Posts: 12
eo_support wrote:
Hi,

You are calling EvalScript too soon. LoadUrl starts loading the page and returns immediately. So by the time you call EvalScript the page has not finished loading yet. You can try to change LoadUrl to LoadUrlAndWait and see if it works for you.

Thanks!



Not for this reason. In fact, JS is controlled by a separate button in my code

eo_support
Posted: Thursday, July 9, 2020 8:04:19 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

You can use the built-in debugger to debug the page to find out why your JS code if failing:

https://www.essentialobjects.com/doc/webbrowser/advanced/debug.aspx

Thanks!
sexfio
Posted: Thursday, July 9, 2020 11:06:35 PM
Rank: Member
Groups: Member

Joined: 3/21/2020
Posts: 12

eo_support
Posted: Friday, July 10, 2020 10:01:56 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

You can run TabbedBrowser sample application and then test your code using the sample application's Console window (click the menu button and then select "Console"). There should be no difference between this console window and EvalScript because internally the console window calls EvalScript (see source code in txtScript_PreviewKeyDown in ConsolePanel.xaml.cs). If this console window works and your application does not, then there is something different in your application that you will need to find out.

If this console window does not work either, try the console window in the built-in debug UI. If that works, then you can isolate the problem into a test project and send the test project to us and we will investigate further.

Additionally, please PM us your order number as we will need to verify that as well.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.