我试图自动化测试在web应用程序中呈现的svg图像。在硒中为svg对象捕获contentDocument
的HTML看起来喜欢 -
<object class="svgcanvas" type="image/svg+xml" data="test.svg"><h4>Error loading SVG file</h4>
#document
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -webkit-user-drag: none; -webkit-tap- highlight-color: rgba(0, 0, 0, 0);" viewBox="0 0 1188 840" xml:space="preserve">
<rect x="0" y="0" width="1188" height="840" style="stroke:none; fill:white"/>
<circle cx="20" cy="830" r="0.144857" style="stroke:#E50033; stroke- width:0.339429"/>
<g id="XMP_1" style="stroke:#000000; stroke-width:0.339429">
<path d="M554 401L641 401" style="stroke:#0000FF; stroke-dasharray: 3.5640 3.5640 3.5640 3.5640"/>
</g>
</object>
我尝试使用下面的代码来获取SVG对象,但svgElement引发以下错误:
'((OpenQA.Selenium.Remote.RemoteWebElement)svgElement).Displayed' threw an exception of type 'OpenQA.Selenium.StaleElementReferenceException'
IWebElement objectTag = _webDriver.FindElement(By.CssSelector("object.svgcanvas"));
IJavaScriptExecutor js = (IJavaScriptExecutor)_webDriver;
string findingSVG = "return arguments[0].contentDocument;";
var svgElement = js.ExecuteScript(findingSVG, objectTag);
那么,有没有一种方法测试在对象标签中嵌入了SVG的页面?
任何帮助非常感谢。
陈旧的元素通常意味着你发现了元素之后和之前调用对该页面重新加载/更改的任何操作。确保页面已加载并完成所有请求。 – lauda
在开始尝试操纵SVG之前,需要一种方法来确保SVG和主DOM已加载。 Google(或StartPage):selenium等待页面加载javascript – MikeJRamsey56
是否在'isDisplayed()'行引发异常?帧内是否有'