mercredi 29 mars 2017

How to simulate a button click using HttpClient

I am trying to navigate to a REST API, however the owner of the web page has inserted an HTML message page in front of the REST API URL. So, when I make the request to the REST API, instead of being returned the XML file that I requested, I get back an HTML page that has some informational message on it, and requires a button click to acknowledge the message.

The button itself, when inspected with Fiddler, shows no onclick event:

<div class="dialog-buttons">
    <button id="frmMessages:btnAcknowledge" name="frmMessages:btnAcknowledge" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="" title="Acknowledge and continue" type="submit">
        <span class="ui-button-text ui-c">OK</span>
    </button>
</div>

I am not able to navigate directly to the page where the button-click sends you, because it doesn't send you anywhere, it just acknowledges that you clicked the button, and closes the message.

I am trying to simulate this button click. I have tried using a System.Windows.Forms.WebBrowser class, but I have not been able to load my resultContent into the Browser, the DocumentText property remains empty, so when I try to invoke the button click, I get a null reference exception.

System.Windows.Forms.WebBrowser b = new System.Windows.Forms.WebBrowser();
b.Navigate("about:blank");
HtmlDocument doc = b.Document;
doc.Write(string.Empty);
b.DocumentText = resultContent;
var resp = b.Document.GetElementById("frmMessages:btnAcknowledge").InvokeMember("onclick");

It seems to me that the owner of the web page screwed something up here by inserting the HTML message page in front of a REST API call, and I have contacted them about that, however between now and when they can fix it (if it is even an issue to them) I need a method of bypassing this message box.




Aucun commentaire:

Enregistrer un commentaire