I have a site which get information of user in one of its pages.
every user has a card which contain his information. I want to write a windows application in Visual C# which read the card and fill web form using those data.
for this reason I have to run a browser in my windows application and run some javascript code to fill that elements in that browser.
does any one how can I run a browser and give to that specific javascript (in url after on page has been loaded) to fill the form?
There is a WebBrowser control that you can use in your windows app. As for populating the information on a web page, I would just pass the userID in QueryString to the URL of the page you create (in your WebBrowser control), and in the page add code to retrieve the user information and display it.
Here is some info on the WebBrowser control:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx
My guess is you would be better off handing over the data you want to see in the web forms via http post or get. Then let the serverside write the values into the propper forms.
Related
browserContainer.EvaluateScriptAsync("document.querySelector('input[id=auth-modal-email]').value='****#gmail.com';");
browserContainer.EvaluateScriptAsync("document.querySelector('input[id=auth-modal-current-password]').value='*****';");
browserContainer.EvaluateScriptAsync("document.querySelector('button[type=submit]').click();");
I've been trying to login a website. I can see that id and password are being filled when I run the application and show it on panel. I also tried on BBC iplayer to understand whether it is related to javascript or not however it was working fine on BBC iplayer login screen.
The website: https://www.cars.com
The website uses custom html components. Some of the html elements within those custom components cannot be accessed directly. You first have to find the custom component and then work from there.
Here is code that works for the submit button in the login form (assuming the login form is visible):
document.querySelector('cars-auth-modal').shadowRoot.querySelector('ep-button').click();
This question probably exist in different forms but I would need to get explained to me how to accomplish the following...
I'm working on a windows forms application (C#). When I click a button on the form I want to navigate to a specific page (all in code behind), find an input[type=text] on that page by id or class, input a password, and click on the login button next to the input.
Then I need to wait for the page that will load after the login button is clicked before I continue identifying more elements. F.e I want to find a html table and traverse it.
If someone could give me a good example and tell me if I need any additional controls in my form I would be most grateful.
Now, as I wrote above, I'm not interested in opening a browser and navigating to that page. I want it all to take place in the code so to speak..
Thanks in advance!
You don't need to scrape the website and find the input of type=text. Forms works with GET or POST requests. Login form is generally a POST request to the server, you should search for the form inside that page and see where it points the action. Let's say it is done this way:
<form action="login.php" method="post">
So you know that login.php will handle the request and that it's using the post method.
Now you should write some C# code to send a POST request to http://yoururl.com/login.php (Please see HttpWebRequest).
Once you get that, since it's a login, you should find a way to keep cookies active so that you can send another request to the page you have to access after the login. Keeping cookies active means that you're logged and your session is active with the user you logged in the previous POST request.
To achieve this part you should have a look to HttpWebRequest.CookieContainer.
Once you get your cookies you should now send a GET request to the next page where you can then scrape the information you need. The GET request to a web page send you the whole html page as response. You should then use a scraping library such as HttpAgilityPack to get the table you need.
Try to write some code and come back when you face a problem, opening another question. I hope I provided you some useful information!
I created a program in c# with webbrowser control that opens a web site and the user will be automatically logged in. That works. However the user should also browse through different web site sections and that's where I get a problem. There is a button on one page "print preview" and what it does in "normal browser" (IE or Mozilla) it opens a new tab and shows the contents. In my program it opens Internet Explorer (it is the default browser) and shows me login page again. Can anyone explain how to open a new tab in my webbrowser control (or new window) and pass login data.
Thank you.
It can't be done the way you are trying to do it. There is no concept of tabs in the web browser control. You can verify this by loading up an html page that makes calls to window.open() in javascript. If that call is made it will just launch an instance of IE that navigates to that particular URL.
Your best bet is to have multiple web browser controls and pass data between them. Either that or use HttpWebRequest.
Although, depending on what you are trying to do you may want to automate IE instead.
With WebClient.DownloadString method it's fairly simple to load normal web page source to string.
But is there any easy way to load those pages which extends and loads new content when you scroll down to end?
You cannot "download" such a page, as it doesn't exist in full form. Such pages require user interaction.
You can use one of the forms of the WebBrowser control to browse to, and programmatically interact with a web site.
hey you can try this approach if you want to do it webclient..
See here.. basically he is using the scrapy but this approach can be adopted in case of webclient to i think so.
basically he is using the firebug or chrome developer tool in order to trace the ajax web request after knowing the web request you can get the content with webclient.
My application (C#) consists of an embedded web browser which will load a page in HTML from a server. The HTML page will be created from scratch for this particular application. My intention is to have the following procedure:
A user opens the application
A web browser embedded within the application will load an HTML page
User will click a button on the HTML page
A C# function (on client side) is triggered from this action
function does some work
send a list of data back to the web page
Web page will retrieve this data and display it
user's browser will be refreshed to display the new page
Now my questions are the following:
How can a C# function on the client side be triggered when a button is clicked on a server page
What is the best way to transfer data (will probably be object)
how can a function on the HTML page wait for data to be received before continuing to execute the function?
Using the WebBrowser control, you can use the ObjectForScripting property. This will allow JavaScript to call C# code using window.external.C# MethodName
There's some quirks with the serialization you might need to work through, and you might need to use webbrowser.Document.InvokeScript to trigger your data back to JavaScript (I've not personally used the result of a window.external call so cannot speak for it).