C# Selenium - 无法访问另一个标签中的图像网址

spo*_*ons 5 c# selenium

我正在尝试验证网站上的图像,但无法访问图像的网址。大多数网站的图像都会带有“src”标签,但该网站的 url 嵌入在另一个标签中。

iv 用于return driver.FindElement(By.ClassName("p-image__image--contain"));访问元素并用于GetAttribute("style");访问图像url。然而给出的唯一信息是background-position: center center;

html格式

Mat*_*ewG 1

当您使用 时GetAttribute("style"),它只会返回style元素上实际属性中的内容,但许多 CSS 属性实际上是使用class样式表或其他方式应用的。因此,您应该使用该GetCssValue方法,如下所示:

element.GetCssValue("background-image")