Accessing svg dom
Hello, I am trying to protractor test a page with graphical image developed using SVG, and below is how I am trying to get one of the id's. expect(driver.isElementPresent(protractor.By.id('v_4'))).toBe(true);
Below is part of the graphics dom. As you can see there are id's, which I should be able to get to, but can't seem to. Can you please let me know what I am doing wrong? Or this is not a supported feature of protractor?
Thanks, Divya
<svg id="v_4" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" version="1.1" width="400" height="600">
<g id="v_5" class="viewport">
<g id="j_1" class="element basic Rect" model-id="b167121f-bf3e-473f-8b72-443c498ef6a8" fill="#FFFFFF" stroke="none" transform="translate(250,50)">
<g id="v_10" class="rotatable" transform="rotate(0,50,15)">
<g id="v_13" class="scalable" transform="scale(100,30)"> … </g>
<text id="v_12" font-size="11" fill="white" font-family="Arial, helvetica, sans-serif" font-weight="bold" y="0.8em" transform="translate(15.5,8.5) ">
MAIN_INPUT
</text>
</g>
</g>
<g id="j_2" class="element basic Rect" model-id="976ffe5a-9e35-45e2-90e4-2539fba6a2bd" fill="#FFFFFF" stroke="none" transform="translate(250,250)"> … </g>
<g id="j_3" class="element basic Rect" model-id="9c9311a2-5f97-4b65-ae3e-536977402df2" fill="#FFFFFF" stroke="none" transform="translate(0,250)"> … </g>
<g id="j_4" class="element basic Rect" model-id="a6ce602d-7f8f-4554-96a1-7fd529759497" fill="#FFFFFF" stroke="none" transform="translate(250,450)"> … </g>
<g id="j_5" class="link" model-id="b9ec5170-f2e1-4957-84bc-f3ea9e4e29fa"> … </g>
<g id="j_6" class="link" model-id="6504ed35-113b-4998-8ebb-2903a9d69738"> … </g>
<g id="j_7" class="link" model-id="77733002-305e-4eac-b017-106706584feb"> … </g>
<g id="j_8" class="element basic Rect" model-id="01c63b9b-b730-4f58-b822-0932f999597d" fill="#FFFFFF" stroke="none" transform="translate(250,10)"> … </g>
</g>
</svg>
How are you loading the SVG into your page?
Also, maybe silly, but worth noting that your example asks for an id v_4, which isn't present in the svg you show.
for some reason even though I put the svg element in my previous comment it does not seem to show up in the issue.
svg id="v_4" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" version="1.1" width="400" height="600"
@DivyaAshok Check out this article for help on how github uses markdown to parse comments: https://help.github.com/articles/github-flavored-markdown
And to be clear - this is inline svg? Or are you loading it inside an object or embed tag?
Thanks for replying Julie, also this is not an angular page either. On load of the page, we are creating svg objects into a svg container via JointJS based on a json object in local storage.
If you go to the page and open firebug or the chrome devtools, can you access the element by doing document.querySelectorAll('#v_4')? I wonder if the way JointJS is embedding the svg is hiding it.
Huh? How are you running that?
I know why I got the error I got, cause document is not a defined variable. I tried to put that in my protractor test code, my bad.
Could you please walk me through how I would do document.querySelectorAll('#v_4') in firebug. I could not figure that out. Sorry.
Thanks, Divya
Please read https://developers.google.com/chrome-developer-tools/ for doing this in Chrome, or
https://developer.mozilla.org/en-US/docs/Tools/Web_Console for doing this in Firefox.
Yes I can access these id's in firebug and chrome dev tools.
document.querySelectorAll("#v_4") svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" version="1.1" id="v_4" width="400" height="600">…</svg
i tried couple more elements via document.querySelectorAll and I am able to access them.
My guess is that the test is not waiting for your SVG to be drawn. Protractor will wait for Angular to finish all of its processing before moving forward (for example, it waits for all $timeout and $http requests to finish), but maybe however you're making the SVG is not something that Angular knows about.
You could test this by adding a browser.sleep(2000) before you try the isElementPresent call. (Note that you don't want to leave sleeps in your final tests, but it's OK to use them for debugging). If that passes, then you've got a synchronization problem.
Thanks, sleeping worked for now.