SimpleBrowserDotNet/SimpleBrowser

Add certificate file (.pfx) to browser to navigate to website.

Closed this issue · 7 comments

Hi there. I saw a code before where there is available the method DefaultCertification for Browser class, but I can't see it, is it not available anymore? How can I call a .pfx file to be able to navigate to a website that needs certificate to connect?

Thanks.

I've searched every version of Browser.cs back to the first check-in. I don't see "DefaultCertification" in the file history. It doesn't appear that this has ever been implemented. That being the case, it would appear that SimpleBrowser does not currently support loading certificates from a .pfx file.

It seems like a relatively straight forward feature to add. It would take updating the Browser class, the WebRequestWrapper class, and the IHttpWebRequest interface. I would code it to work like Chrome - where many PFX files can be loaded at once. "DefaultCertification" (singular) sounds like it would only handle one at a time. This is probably enough for most applications, but seems limiting. Chrome handles multiple. So should SimpleBrowser.

My availability is limited for at least the next week. Contributions are gladly accepted.

I was able to code this over the last day. My only problem is that I don't have a way to test it. I can generate a pfx and add it to the browser certificate store and request easily enough, but I can't verify that the certificate is being applied properly when browsing to a web site.

@jairofranchi Still with me? I haven't received a response.

Hello Kevin, sorry the late. I was able to use the certificate. I found a project that was using SimpleBrowser and it was passing the certificate and password on Navigate method. I imported the simplebrowser.dll that it was using and now I can use the navigation with certificate. I think that it was an old version of simplebrowser that had this before. My problem now that I'm did not find how to upload file to a website. On my automation I connect to a website that needs to add some files, and on the button Load Files, it opens another frame that have the button Load File where it opens the Save Dialog to inform the file. How can I do this, is it possible with SimpleBrowser?

SimpleBrowser supports uploading via an input HTML element of type file. For example:

<input type="file" name="img">

The button to load files may use the file input element to select the upload files. If you inspect the HTML on the page, do you see these file input elements?

Kevin

Yes, I see it on the button:
<input type="file" name="files[]" multiple="">
But the problem is that it is inside another frame that is opened with a button called Load File:

<button class="btn btn-small btn-primary" type="button" style="width:180px;" onclick="javascript:cryo_UploadCrypt('13Oim3AU5Psxm8mVkjo3SIjstL6QFxYgZu6PzsD3zZCBnuSjMEZCv+9WoHQ19jOh1hrGSqvDb+xgJY6QHLJm6/1LlYXMf33x');"> Carregar novo arquivo </button>

How I will inform the files that will be loaded to the input in this case?

Using the file input is as easy as:

HtmlResult fileInput = browser.Find("input", new { name = "files[]" });
fileInput.Value = @"c:\path\to\your\file";

You would then typically submit the form.

In your case, however, there is the onclick event handler that executes JavaScript. SimpleBrowser does not support JavaScript. It may be possible to duplicate what the JavaScript is doing or ignore the JavaScript entirely. I would have to see the JavaScript to know.