简体   繁体   中英

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 ?

如果您已经知道映像的URL,则可以使用System.Net命名空间中的WebClient类。

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM