いくつかの円と長方形の要素を持つ SVG オブジェクトがあります。webdriver を使用すると、メインの svg オブジェクトをクリックできますが、その中のどの要素もクリックできません。getAttribute() を使用して幅、ID、x/y、テキストなどの値を返すことができるため、問題はクリック (またはマウス操作) にのみあるようです。
HTML の例を次に示します。
<div id="canvas">
<svg height="840" version="1.1" width="757" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative;">
<image x="0" y="0" width="757" height="840" preserveAspectRatio="none">
<circle cx="272.34" cy="132.14">
<rect x="241.47" y="139.23">
<text style="text-anchor: middle; x="272.47" y="144.11">
</svg>
</div>
WebDriver が四角形要素を右クリックしようとしている (そして失敗している) 例:
WebElement mapObject = driver.findElement(By.xpath("//*[name()='svg']/*[name()='rect']"));
Actions builder = new Actions(driver);
builder.contextClick(mapObject).perform();
しかし、これは機能し、値を返します:
driver.findElement(By.xpath("//*[name()='svg']/*[name()='rect']")).getAttribute("x");
WebDriver エラーの場合、通常は次のようになります。
org.openqa.selenium.WebDriverException: '[JavaScript Error: "a.scrollIntoView is not a function" {file: "file:///var/folders/sm/jngvd6s97ldb916b7h25d57r0000gn/T/anonymous490577185394048506webdriver-profile/extensions/fxdriver@googlecode.com/components/synthetic_mouse.js" line: 8544}]' when calling method: [wdIMouse::move]
私はこれを調査するのに時間を費やしましたが、Selenium と SVG ではやや一般的な問題のようですが、回避策があるかどうか疑問に思っています。私が見つけた唯一の解決策は、SVG 自体と対話することであり、これは既に実行できます。
Java + Firefox 17でSelenium 2.28を使用しています(2.29を試しました)。
どんなアイデアでも大歓迎です。