kakopappa
kakopappa

Reputation: 5085

how to make a WatiN internal http request?

just wonder whether it's possible to make an internal extra request to an image without using separate code. eg,

var browser = new IE();
string url = "https://www.google.com/"
browser.GoTo(url);

// extract http://www.google.com/images/logos/ps_logo2.png 
//using a http request using browser ?

browser.Images wont let me save the image :|, how can I make an external request to get the image ?

Upvotes: 0

Views: 967

Answers (2)

Jeroen van Menen
Jeroen van Menen

Reputation: 2418

Maybe these steps work:

  • Find the image on the page:
var image = browser.Image(Find.First())
  • Get the href and navigate to it
browser.GoTo(image.href);
  • Get a screenshot of the page:
var screenshot= new UtilityClasses.CaptureWebPage(_browser).CaptureWebPageImage(false, false, 100);
  • And then trim the screenshot to the size of the image. To get the Height and Width of the image you need the call
var width = image.Style.GetAttributeValue("width");
var height= image.Style.GetAttributeValue("height");
  • Now you can create a new Image with the correct height and width.

HTH, Jeroen

Upvotes: 0

wsanville
wsanville

Reputation: 37506

If you already know the URL to your image, you can use the WebClient class in the System.Net namespace.

byte[] image = new WebClient().DownloadData("https://www.google.com/images/logos/ps_logo2.png");

Upvotes: 2

Related Questions