0

My supervisor has recently switched us from HP-UFT to Robot with the Selenium Webdriver and I'm finding it extremely difficult to figure out how to use the driver and/or keyword framework to expand a folding tree ul/li webelement.

Below is a stripped out example of the code on the page:

<ul>
<li class="node-class open" id="i1454430045821320">
    <a class="" style="" href="">
    <ins>&nbsp;</ins>Location Header 1</a>
    <ul>
        <li class="node-instance  leaf" id="i1454430058247421">
            <a class="" style="" href="">
            <ins>&nbsp;</ins>Location 1</a>
        </li>
        <li class="node-instance  last leaf" id="i14545337159411690">
            <a class="" style="" href="">
            <ins>&nbsp;</ins>Location 2</a>
        </li>
    </ul>
</li>
<li class="node-class  closed " id="i14544407827351156">
    <a class="" style="" href="">
    <ins>&nbsp;</ins>Location Header 2</a>
</li>

What I'm trying to do should be extremely simple: I want to expand a specifed closed tree structure if it's classed as closed. Beneath each branch is an optional nested branch, or a selection checkbox. My end goal is to be able to drill down to a location in the tree that the tester specifies and click the end leaf.

Using "Click Element|xpath=/ul/li[a[contains(text(),'Location Header 2')]" does expand the branch but it also selects all of the child node checkboxes.

In UFT, if I hit this kind of problem I'd simply change the parent <li> class to force it open (if I couldn't click or use any of the other methods to drill down and select).

In Robot, I can use the keyword "Get Element Attribute" to READ the class, but I don't see a keyword to CHANGE it so that idea is out. What I'm looking for is a way to expand the tree branches without inadvertently selecting all of the child nodes.

The drilling down through the tree portion I can deal with once I figure out how to open the nodes correctly but opening up the branch without potentially selecting all of the sub-items is making me pound my head into my desk.

I keep thinking that maybe I'm missing something simple. Any assistance on something that I could try would be greatly appreciated.

kheffner
  • 31
  • 9
  • can you show us your current code? I'm not too familiar with doing exactly what you want to do, but your locator wouldn't be the most solid, I'm assuming when you do this manually, all the sub-items aren't getting selected? – shicky Feb 11 '16 at 15:56
  • "Click Element xpath=/ul/li[a[contains(text(),'Location Header 2')]" That's the keyword and parameters that I'm using to select the second header branch. When I do that, however, it expands the nested li elements... and selects all of the sub-items. I *think* the problem is that the default behavior for the particular element is if you click on it, all sub-items are selected. The only way to avoid this manually is to click the expand/contract "arrow" to the left of the header... but that's not an element that I can interact with in Robot since it's not actually in the viewable code. – kheffner Feb 11 '16 at 16:18
  • okay so currently its following the default behaviour which is cool. So there's an arrow to the left of the header, I'm assuming this is javascript? If so this isn't a problem, you can use jquery to locate the element for one – shicky Feb 11 '16 at 16:24
  • have you tried clicking the element? looks like it might be the placeholder for your "expand/contract "arrow" to the left". Try `Click Element xpath=//ul/li[a[contains(text(),'Location Header 2')]/a/ins` – jim Feb 11 '16 at 19:13
  • Jim: I just tried with the additional /a/ins objects and it continues to do the same behavior. Clicking it selects all sub-items. Ugh. – kheffner Feb 11 '16 at 19:28
  • Schicky: you lost me at using jquery. Could you please explain? Please? – kheffner Feb 11 '16 at 19:29
  • well you say the element is not viewable in the code, what do you mean by that? I assumed you meant this is handled via javascript. If so, you can use jQuery to locate elements. Look at - http://robotframework.org/Selenium2Library/doc/Selenium2Library.html – shicky Feb 12 '16 at 10:24
  • You haven't stated whether the child node checkboxes are selected when you expand a node manually. If they are not selected, I would try recording a script with Selenium IDE and compare to what you tried. If they are selected then you can try manipulating the class or state of the elements via Execute Javascript - see http://stackoverflow.com/questions/195951/change-an-elements-class-with-javascript. – ombre42 Feb 12 '16 at 15:32
  • Expanding the tree manually by clicking the header *does* select all of the child nodes. The only way to expand without selection is to click an arrow so that it unfolds. Personally I think it's bug but that's the way the project manager wants it. I was hoping for a way to hit the element at the DOM level like I've done with other Ajax controls in the past (in UFT) -- which Execute Javascript might be able to do if I can figure out the implementation. Thanks! Off to try the idea! – kheffner Feb 12 '16 at 19:14
  • update: _Execute JavaScript document.getElementsById("i14544407827351156").setAttribute("class","node-class-open")_ does not force the element open unfortunately. It is, however, changing the class attribute. Still pounding on this to try to make it work. – kheffner Feb 12 '16 at 21:11
  • I have a wild guess, that what you need is to click on a `:before` pseudo-element, which is not accessible via `xpath` (they never are). But in order to prove or dismiss it, we need either my direct access to the web page or your familiarity with `css` selectors. Please decide which of those is more convenient for you and let me know. – jim Feb 16 '16 at 20:30
  • Unfortunately, access to the page isn't possible; it's behind a firewall and not open for public consumption. I'm still working on this even though I think it's going to prove fruitless. :( – kheffner Feb 16 '16 at 21:45
  • Still working on this and I have a question: Could I use the _Click Element At Coordinates_ keyword somehow? I've been trying to do this against the _
  • _ object in the example but it's still expanding and selecting all sub items. _Click Element At Coordinates | xpath=//ul/li[a[contains(text(),'Location Header 2')] | 1 | -5_ should click on the expand arrow that is directly to the left of the object, correct?
  • – kheffner Feb 17 '16 at 15:29