Reputation:
I'm navigating to a website with some parameters passed inside the URL which gives me the required info displayed on the site we navigate to. Then on the site there is an input button 'export data' which then saves the data into a nice csv file. All I need to do is automate the 'Click' of the button. I usually code in VBA so I would loop through Document.elements to get the button then simply click but as I am developing this system with asp.net web forms and I'm finding it a bit more tricky. Trouble is I don't know how to store/get the open browser page as a variable in order to click the button. Below is the code I have which you can see is very simple.
using System;
using System.Web.UI.WebControls;
namespace myNameSpace
{
public partial class DataScrape : System.Web.UI.Page
{
protected void Proceed_Click(object sender, EventArgs e)
{
Response.Redirect(url_with_params);
//Need to click a button on the redirected page.
}
}
}
Upvotes: 0
Views: 355
Reputation: 411
This may not be helpful if for whatever reason "clicking" a button via codebehind is a hard requirement (I've never tried to do that), but I would suggest pulling the functionality out of the onclick of the button and putting it in a separate function. Then you can call that separate function whenever you want, including on page_load. If you still need the button there for the user to initiate the click, the onclick of the button can also call that separate method.
Upvotes: 0