Invoke a tag javascript click function from Webclient
You cannot execute javascript from WebClient
. You can simulate such request and achieve the required response from the server but it takes some reverse-engineering.
To understand how to get the desired response from the server first you have to perform this operation through browser and record request that is generated by clicking on that link (for that you can use Fiddler Web Debugger). Than you have to recreate such request from your WebClient
, that is - send all the required data to the server properly formatted, along with cookies and correct request type (GET or POST - synchronous or asynchronous).
Why you cannot use WebClient
for javascript execution is nicely described here
And how you can create a request that resembles the one created by javascript click can be deduced from this.
HtmlUnit How to get a page after executing JavaScript
Yes you are right, the method getNewPage() was removed with the version 2.33 as part of a a huge refactoring regarding event handling.
As replacement you can use the enclosed page of the window.
E.g. if you are sure that the resulting page is in the same window as your current page (has replaced your page without opening a new window), you can use
page.getEnclosingWindow().getEnclosedPage()
If your code might opend up a new window it will be more save to ask the webClient for the current window (newly opened windows are automatically marked as the current)
page.getWebClient().getCurrentWindow().getEnclosedPage()
Or in your code sample you can directly use the client
webClient.getCurrentWindow().getEnclosedPage()
Hope that helps.
c# get content loaded by js from url
WebClient and DownloadString will just download the content of the page as string, to be able to run the JavaScript code on this page, you will need an object which understand DOM and can run JavaScript, this will be a browser.
Some more information about this subject:
Running Scripts in HtmlAgilityPack
Load a DOM and Execute javascript, server side, with .Net
Related Topics
Sending a Value from Server to Client with Sockets
Are Get and Set Functions Popular with C++ Programmers
How to Dllexport a C++ Class for Use in a C# Application
Xamarin Android Alarm Manager Issue
Calling a SQL User-Defined Function in a Linq Query
Creating Simple C++.Net Wrapper. Step-By-Step
Sort Datagridview Columns in C#? (Windows Form)
How Can Synchronizationcontext.Current of the Main Thread Become Null in a Windows Forms Application
Deploying ASP.NET Web Forms Project to Fedora 24
Non Client Painting on Aero Glass Window
How to Share Sessions Between PHP and ASP.NET Application
What's the Best Way to Do a Backwards Loop in C/C#/C++
Linq-To-Sql: Recursively Get Children
How to Return Dynamic Object from SQL Query
C# Dllimport with C++ Boolean Function Not Returning Correctly