我試圖自動化測試在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()'行引發異常?幀內是否有'