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();
Related
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.
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.
I have a project where I am trying to login to sprint and then do some screen scraping to get data about the different lines that the company controls. I have tried passing the cookies that are provided by the initial website call in the initial HttpWebRequest form post, but I do not get any cookies back that will denote user or session or anything. In fact, if I then try to use the WebClient class to get the landing page, the response url that I get back is the login page.
I think it is due to the fact that when you login, you get redirected to a page that does some processing and then redirects you to the landing page. I am passing in correct credentials and don't know where it is failing. Can anyone help me so that I do not need to use Watin or any other browser control to scrape that data as that will be too slow.
Use Selenium.
It is normally for website testing, but you easily use it for your situation.
It allows you to launch a browser and programmatically control mouse clicks and keyboard presses to do exactly what you need.
You also run xpath on the HTML to read data, or even run custom javascript on pages if you need to get more complicated.
I am building a silverlight application that needs to have a login page and if the details are correct I need to redirect the user to the actual application. What would be the best way to proceed? This will be my first silverlight app.
I was thinking of having a login page that redirects the user to another page that uses the silverlight navigation framework to switch the content pages after the user has logged in.
Any better way?
Thanks!
May be you need Silverlight Business Application.
Template for this is available on VS 2010.
It has login, register user logics, and have navigations.
It is more secure to encase the security into your outer frame window than view page navigation.
A common approach is to have LoggedIn and LoggedOut states for that view (using the VisualStateManager to change it). The LoggedOut state shows the login panel. The LoggedIn shows your main frame windows.
This way you can reach your site via any URL (assuming deep linking) and still get your security.