我需要使用chromedriver对Selenium C#中的整个元素进行截图。 元素是表格,尽管我正在获取元素的宽度和高度,但我得到的屏幕截图只有15行。
IWebElement element = driver.FindElement(By.XPath("Xpath of the element")); string fileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") +".jpg"; Byte[] byteArray = ((ITakesScreenshot)driver).GetScreenshot().AsByteArray; System.Drawing.Bitmap screenshot = new System.Drawing.Bitmap(new System.IO.MemoryStream(byteArray)); System.Drawing.Rectangle croppedImage = new System.Drawing.Rectangle(element.Location.X, element.Location.Y, element.Size.Width, element.Size.Height); screenshot = screenshot.Clone(croppedImage, screenshot.PixelFormat); screenshot.Save(String.Format(@"path" + fileName, System.Drawing.Imaging.ImageFormat.Jpeg));