I am trying to automate a test using SVG Nodes. I need to click on a particular node.
I click on the element in Firefox, click F12 to get the console up, & type console.dir($0) to see the details. This is what the element looks like:
text
__data__: Object { height: 0, depth: 1, x: 0, … }
attributes: NamedNodeMap [ fill="#fff", font-size="36px", font-family="mapicons", … ]
baseURI: "https://fnord.co.uk/#/jobs/add/job?@=-702x6714391y19z&lf=1!19.73740"
childElementCount: 0
childNodes: NodeList [ #text ]
children: HTMLCollection []
classList: DOMTokenList []
className: SVGAnimatedString { baseVal: "", animVal: "" }
clientHeight: 0
clientLeft: 0
clientTop: 0
clientWidth: 0
dataset: DOMStringMap { }
dx: SVGAnimatedLengthList { baseVal: SVGLengthList, animVal: SVGLengthList }
dy: SVGAnimatedLengthList { baseVal: SVGLengthList, animVal: SVGLengthList }
farthestViewportElement: <svg id="svgstruct" style="position: relative; overflow: visible; margin-top: 50px; margin-left: 20px; min-width: 100%;" width="100%" height="100%">
firstChild: #text ""
firstElementChild: null
id: ""
innerHTML: "\ue05e"
isConnected: true
lastChild: #text ""
lastElementChild: null
lengthAdjust: SVGAnimatedEnumeration { baseVal: 1, animVal: 1 }
localName: "text"
namespaceURI: "http://www.w3.org/2000/svg"
nearestViewportElement: <svg id="svgstruct" style="position: relative; overflow: visible; margin-top: 50px; margin-left: 20px; min-width: 100%;" width="100%" height="100%">
nextElementSibling: null
nextSibling: null
nodeName: "text"
nodeType: 1
nodeValue: null
onabort: null
onanimationcancel: null
onanimationend: null
onanimationiteration: null
onanimationstart: null
onauxclick: null
onblur: null
oncanplay: null
oncanplaythrough: null
onchange: null
onclick: null
onclose: null
oncontextmenu: null
oncopy: null
oncut: null
ondblclick: null
ondrag: null
ondragend: null
ondragenter: null
ondragexit: null
ondragleave: null
ondragover: null
ondragstart: null
ondrop: null
ondurationchange: null
onemptied: null
onended: null
onerror: null
onfocus: null
ongotpointercapture: null
oninput: null
oninvalid: null
onkeydown: null
onkeypress: null
onkeyup: null
onload: null
onloadeddata: null
onloadedmetadata: null
onloadend: null
onloadstart: null
onlostpointercapture: null
onmousedown: null
onmouseenter: null
onmouseleave: null
onmousemove: null
onmouseout: null
onmouseover: null
onmouseup: null
onmozfullscreenchange: null
onmozfullscreenerror: null
onpaste: null
onpause: null
onplay: null
onplaying: null
onpointercancel: null
onpointerdown: null
onpointerenter: null
onpointerleave: null
onpointermove: null
onpointerout: null
onpointerover: null
onpointerup: null
onprogress: null
onratechange: null
onreset: null
onresize: null
onscroll: null
onseeked: null
onseeking: null
onselect: null
onselectstart: null
onshow: null
onstalled: null
onsubmit: null
onsuspend: null
ontimeupdate: null
ontoggle: null
ontransitioncancel: null
ontransitionend: null
ontransitionrun: null
ontransitionstart: null
onvolumechange: null
onwaiting: null
onwebkitanimationend: null
onwebkitanimationiteration: null
onwebkitanimationstart: null
onwebkittransitionend: null
onwheel: null
outerHTML: "<text fill=\"#fff\" font-size=\"36px\" font-family=\"mapicons\" transform=\"translate(0,30)\">\ue05e</text>"
ownerDocument: HTMLDocument https://alloy-labs.yotta.co.uk/#/jobs/add/job?@=-702x6714391y19z&lf=1!19.73740
ownerSVGElement: <svg id="svgstruct" style="position: relative; overflow: visible; margin-top: 50px; margin-left: 20px; min-width: 100%;" width="100%" height="100%">
parentElement: <g class="node" cursor="pointer" transform="translate(30,110)">
parentNode: <g class="node" cursor="pointer" transform="translate(30,110)">
prefix: null
previousElementSibling: <path d="M0,0a30,30,0,1,0,0,60h0a30,30,0,1,0,0,-60Z" fill="#f5c041">
previousSibling: <path d="M0,0a30,30,0,1,0,0,60h0a30,30,0,1,0,0,-60Z" fill="#f5c041">
requiredExtensions: SVGStringList { length: 0, numberOfItems: 0 }
requiredFeatures: SVGStringList { length: 0, numberOfItems: 0 }
rotate: SVGAnimatedNumberList { baseVal: SVGNumberList, animVal: SVGNumberList }
scrollHeight: 0
scrollLeft: 0
scrollLeftMax: 0
scrollTop: 0
scrollTopMax: 0
scrollWidth: 0
style: CSS2Properties { }
systemLanguage: SVGStringList { length: 0, numberOfItems: 0 }
tabIndex: -1
tagName: "text"
textContent: "\ue05e"
textLength: SVGAnimatedLength { baseVal: SVGLength, animVal: SVGLength }
transform: SVGAnimatedTransformList { baseVal: SVGTransformList […], animVal: SVGTransformList […] }
viewportElement: <svg id="svgstruct" style="position: relative; overflow: visible; margin-top: 50px; margin-left: 20px; min-width: 100%;" width="100%" height="100%">
x: SVGAnimatedLengthList { baseVal: SVGLengthList, animVal: SVGLengthList }
y: SVGAnimatedLengthList
animVal: SVGLengthList { numberOfItems: 0, length: 0 }
baseVal: SVGLengthList
length: 0
numberOfItems: 0
__proto__: SVGLengthListPrototype { clear: clear(), initialize: initialize(), getItem: getItem(), … }
__proto__: SVGAnimatedLengthListPrototype { baseVal: Getter, animVal: Getter, … }
__proto__: SVGTextElementPrototype
constructor: ()
length: 0
name: "SVGTextElement"
prototype: SVGTextElementPrototype { … }
Symbol(Symbol.hasInstance): undefined
__proto__: function ()
__proto__: SVGTextPositioningElementPrototype
I tried finding it using find by classname, but that didn't work:
String className="SVGAnimatedString";
List<WebElement> cardTitles = driver.findElements(By.className(className));
Evidently className does not mean this kind of className?
So I tried finding it using cssSelector. This works, but is less useful, as the CSS Selector changes each time screen loads. Having found my element , if I click it just using element.click, nothing happens. If I click on it using this Javascript, it throws an exception:
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
The exception message:
org.openqa.selenium.JavascriptException: TypeError: arguments[0].click is not a function
How do I get the click to work on this element?
This is NOT a duplicate of Selenium WebDriver [Java]: How to Click on elements within an SVG using XPath
Unlike that enquirer, I have managed to find my element.
My problem is with clicking that element.
Browser: Firefox Quantum 59.0.1 (64-bit) Geckodriver: 0.19.1 Selenium Jar: 3.8.1