Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium C#如何找到图像的删除?_C#_Selenium_Findelement - Fatal编程技术网

Selenium C#如何找到图像的删除?

Selenium C#如何找到图像的删除?,c#,selenium,findelement,C#,Selenium,Findelement,我正在做一个拍摄产品图片的项目。 然后裁剪并保存此图像 这是密码 Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot(); using (var ms = new MemoryStream(screenshot.AsByteArray)) using (var imgShot = Image.Fro

我正在做一个拍摄产品图片的项目。 然后裁剪并保存此图像

这是密码

                    Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot();

                    using (var ms = new MemoryStream(screenshot.AsByteArray))
                    using (var imgShot = Image.FromStream(ms))
                    using (var src = new Bitmap(imgShot))
                    {
                        IWebElement element = driver.FindElement(By.Name("viewport"));
                        Rectangle cropRect = new Rectangle(element.Location.X, element.Location.Y, element.Size.Width, element.Size.Height);

                        var clone = src.Clone(cropRect, src.PixelFormat);
                        clone.Save(_SavePath);
                    }
参考下面的图像链接,我将如何使用C#Selenium driver.FindElement来选择此图像: 这就是我试图使用的:
IWebElement元素=driver.FindElement(按.Name(“视口”)

图片:

以下是图像的HTML代码:

<html><head><meta name="viewport" content="width=device-width, minimum-scale=0.1"><title>ImageServer.aspx (335×328)</title></head><body style="margin: 0px; background: #0e0e0e;"><img style="-webkit-user-select: none;margin: auto;" src="http://dealer.rectron.co.za/ImageServer.aspx?QualifyingProductID=c471d4fd-fd97-48b8-a709-441b18c1830c"></body></html>
ImageServer.aspx(335×328)
当我尝试裁剪图像时,会出现以下异常:

System.ArgumentException:'矩形'{X=0,Y=0,宽度=0,高度=0}'的宽度或高度不能等于0'

我认为我使用FindElement的方式可能是不正确的。
谢谢

您的定位器不正确,您正在创建的
元素没有出现在页面上,也没有维度。您需要按如下方式修复定位器:
IWebElement元素=driver.FindElement(By.XPath(“//img”)