java - Selenium WebDriver: clicking on elements within an SVG using XPath -
i have svg object few circle , rectangle elements. using webdriver, can click on main svg object, not of elements within it. problem seems clicking (or mouse interaction), can use getattribute() return value(s) of width, id, x/y, text, etc, under it.
here example of 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>
and example of webdriver trying right click rectangle element (and failing):
webelement mapobject = driver.findelement(by.xpath("//*[name()='svg']/*[name()='rect']")); actions builder = new actions(driver); builder.contextclick(mapobject).perform();
but works , returns value:
driver.findelement(by.xpath("//*[name()='svg']/*[name()='rect']")).getattribute("x");
when webdriver errors, it's this:
org.openqa.selenium.webdriverexception: '[javascript error: "a.scrollintoview not 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]
i've spent time researching , seems common issue selenium , svgs, i'm wondering if there workaround. solutions i've found interacting svg itself, can do.
i'm using selenium 2.28 (and tried 2.29) w/ java + firefox 17.
any ideas appreciated.
for interested, solved in following ways:
1) testing on osx firefox 17 , selenium 2.28/29, figured out works (at least me) on windows firefox 18 , selenium 2.29
2) interacting svgs standard:
driver.findelement(by.xpath(your xpath)).click();
doesn't work. need use actions.
3) interact svg objects, following xpath works:
"/*[name()='svg']/*[name()='svg object']";
the svg object being under svg element (e.g. circle, rect, text, etc).
an example of clicking svg object:
webelement svgobject = driver.findelement(by.xpath(your xpath)); actions builder = new actions(driver); builder.click(svgobject).build().perform();
note: need call path inside click() function; using:
movetoelement(your xpath).click().build().perform();
doesn't work.
Comments
Post a Comment