我需要使用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));除了这个之外,还有其他方法可以让我看到整个表格的屏幕截图吗?
发布于 2018-04-24 15:56:13
这张桌子有身份证吗?如果是这样的话,您可以使用该id而不是元素名来截取表的屏幕快照吗?
WebElement ele = driver.findElement(By.id("yourTableID"));来自类似的问题(但不是Xpath):How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
似乎意味着你可能需要在拍摄截图之前强迫窗口变大?
this.driver.manage().window().setSize(new Dimension(1680, 1050));发布于 2018-10-22 07:39:56
您可以使用这个包https://www.nuget.org/packages/Noksa.WebDriver.ScreenshotsExtensions/
为了获取元素的屏幕截图,请使用OnlyElementDecorator:
using WDSE;
using WDSE.Decorators;
using WDSE.ScreenshotMaker;
var vcs = new OnlyElementDecorator(new ScreenshotMaker());
var screen = _driver.TakeScreenshot(vcs);https://stackoverflow.com/questions/50005998
复制相似问题