I'm trying to expand a tree of nodes with folder structure using XPath locators
selenium.click("//*[@id='ext-gen15']/li/div/img[1]");
but as the folder structure is not fixed and changes, so XPath expression must change:
selenium.click("//*[@id='ext-gen15']/li/ul/li[1]/div/img[1]");
It worked in TestLink 1.9.2Version as i had an "Expand All" button to directly expand the tree but this button is missing in 1.9Version and i am unable to expand the tree at once. There are more than 750 test cases under multiple folders and to find each xpath to implement would be really tidious. I want to know to how implement to expand tree as the xpaths are changing dynamically. Please note i want to perform this operation on "testlink tool".
Example XPaths:
/html/body/div[1]/div/div/ul/li/div/img[1];
//html/body/div[1]/div/div/ul/li/ul/li[1]/div/img[1];
//html/body/div[1]/div/div/ul/li/ul/li[2]/div/img[1];
//html/body/div[1]/div/div/ul/li/ul/li[2]/ul/li/div/img[1];
//html/body/div[1]/div/div/ul/li/ul/li[2]/ul/li/ul/li/div/img[1];
//html/body/div[1]/div/div/ul/li/ul/li[3]/div/img[1];
//html/body/div[1]/div/div/ul/li/ul/li[3]/ul/li/div/img[1];
//html/body/div[1]/div/div/ul/li/ul/li[4]/div/img[1];
HTML code of the entire tree structure
<div id="tree" class="x-panel x-tree" style="overflow:auto; height:100%;border:1px solid #c3daf9;">
<div id="ext-gen13" class="x-panel-bwrap">
<div id="ext-gen14" class="x-panel-body x-panel-body-noheader" style="overflow: auto;">
<ul id="ext-gen15" class="x-tree-root-ct x-tree-arrows">
<li class="x-tree-node">
<div class="x-tree-node-el x-unselectable x-tree-node-expanded" unselectable="on" ext:tree-node-id="293112">
<span class="x-tree-node-indent"></span>
<img class="x-tree-ec-icon x-tree-elbow-end-minus" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="javascript:SP(293112,0)" hidefocus="on">
<span unselectable="on">
Eden / BIT_Integration_Testing_TestPlan (115)(
<span class="light_not_run" title="Not Run">22,</span>
<span class="light_passed" title="Passed">75,</span>
<span class="light_failed" title="Failed">14,</span>
<span class="light_blocked" title="Blocked">4</span>
)
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="">
<li class="x-tree-node">
<div class="x-tree-node-el x-unselectable x-tree-node-expanded" unselectable="on" ext:tree-node-id="313089">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow-minus" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="" hidefocus="on">
<span unselectable="on">
SanityTest Cases (7)(
<span class="light_not_run" title="Not Run">0,</span>
<span class="light_passed" title="Passed">7,</span>
<span class="light_failed" title="Failed">0,</span>
<span class="light_blocked" title="Blocked">0</span>
)
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="">
<li class="x-tree-node">
<div class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on" ext:tree-node-id="310784">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-elbow-line" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="javascript:ST(310784,310785)" hidefocus="on">
<span unselectable="on">
<span class="light_passed" alt="Passed" title="Passed">
<b>eden-2517</b>
:Verify order for CRIL B2B_US with Elite 1000 having secondary MSISDN of UK.
</span>
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on" ext:tree-node-id="310011">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-elbow-line" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="javascript:ST(310011,310012)" hidefocus="on">
<span unselectable="on">
<span class="light_passed" alt="Passed" title="Passed">
<b>eden-2490</b>
:Verify order via fulfillment partner for B2B_AU with Elite 800 havin secondary MSISDN_US.
</span>
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on" ext:tree-node-id="309782">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-elbow-line" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="javascript:ST(309782,309783)" hidefocus="on">
<span unselectable="on">
<span class="light_passed" alt="Passed" title="Passed">
<b>eden-2484</b>
:Verify order via fulfilment partner for B2B_UK with Elite 1000 having secondary AU MSISDN
</span>
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on" ext:tree-node-id="309858">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-elbow-line" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="javascript:ST(309858,309859)" hidefocus="on">
<span unselectable="on">
<span class="light_passed" alt="Passed" title="Passed">
<b>eden-2486</b>
:Verify order via fulfillment partner for B2B_US with Elite 1000 havin sec MSISDN_UK.
</span>
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on" ext:tree-node-id="311291">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-elbow-line" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="javascript:ST(311291,311292)" hidefocus="on">
<span unselectable="on">
<span class="light_passed" alt="Passed" title="Passed">
<b>eden-2534</b>
:Verify order via Partners(InDirect Channel) for B2C_AUS with prepaid product.
</span>
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on" ext:tree-node-id="311271">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-elbow-line" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="javascript:ST(311271,311272)" hidefocus="on">
<span unselectable="on">
<span class="light_passed" alt="Passed" title="Passed">
<b>eden-2533</b>
:Verify order via Partners(InDirect Channel) for B2C_US with prepaid product.
</span>
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on" ext:tree-node-id="311251">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-elbow-line" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow-end" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="javascript:ST(311251,311252)" hidefocus="on">
<span unselectable="on">
<span class="light_passed" alt="Passed" title="Passed">
<b>eden-2532</b>
:Verify order via Partners(InDirect Channel) for B2C_UK with prepaid product.
</span>
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
</ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-unselectable x-tree-node-collapsed" unselectable="on" ext:tree-node-id="303820">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow-plus" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="" hidefocus="on">
<span unselectable="on">
BIT (74)(
<span class="light_not_run" title="Not Run">3,</span>
<span class="light_passed" title="Passed">55,</span>
<span class="light_failed" title="Failed">12,</span>
<span class="light_blocked" title="Blocked">4</span>
)
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-unselectable x-tree-node-collapsed" unselectable="on" ext:tree-node-id="313071">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow-plus" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="" hidefocus="on">
<span unselectable="on">
E2E Tests (30)(
<span class="light_not_run" title="Not Run">15,</span>
<span class="light_passed" title="Passed">13,</span>
<span class="light_failed" title="Failed">2,</span>
<span class="light_blocked" title="Blocked">0</span>
)
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div class="x-tree-node-el x-unselectable x-tree-node-collapsed" unselectable="on" ext:tree-node-id="322551">
<span class="x-tree-node-indent">
<img class="x-tree-icon" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
</span>
<img class="x-tree-ec-icon x-tree-elbow-end-plus" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<img class="x-tree-node-icon" unselectable="on" src="https://portal.truphone.com/testlink/third_party/ext-js/images/default/s.gif" alt="">
<a class="x-tree-node-anchor" tabindex="1" href="" hidefocus="on">
<span unselectable="on">
DE_SCOPED (4)(
<span class="light_not_run" title="Not Run">4,</span>
<span class="light_passed" title="Passed">0,</span>
<span class="light_failed" title="Failed">0,</span>
<span class="light_blocked" title="Blocked">0</span>
)
</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</body>
On using the provided XPath ,I am getting the error "Element not found". I am attaching the logs for reference.
16:02:14.804 INFO - Command request: getNewBrowserSession[*firefox, https://portal.truphone.com, ] on session null
16:02:14.804 INFO - creating new remote session
16:02:14.851 INFO - Allocated session 1bf2070b72af4d41ba413d5d4f568d24 for https://portal.truphone.com, launching...
jar:file:/C:/Softwares/jars/selenium-server-standalone-2.28.0.jar!/customProfileDirCUSTFFCHROME
16:02:15.163 INFO - Preparing Firefox profile...
16:02:21.097 INFO - Launching Firefox...
16:02:28.562 INFO - Got result: OK,1bf2070b72af4d41ba413d5d4f568d24 on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:28.593 INFO - Command request: windowFocus[, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:28.608 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:28.608 INFO - Command request: windowMaximize[, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:28.655 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
Test Name -- loginTest
total rows -- 2
total cols -- 3
Test Name -- testPlan
total rows -- 2
total cols -- 2
Test Name -- eden_Pass
total rows -- 4
total cols -- 2
username-----password---Y
16:02:28.765 INFO - Command request: open[/testlink/login.php, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:37.556 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:40.554 INFO - Command request: type[//*[@id='login'], rpatel] on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:40.570 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:43.568 INFO - Command request: type[//html/body/div[2]/form/p[2]/input, ak1LbbY[7] on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:43.599 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:46.598 INFO - Command request: click[//html/body/div[2]/form/input[3], ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:47.472 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:52.485 INFO - Command request: waitForPageToLoad[50000, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:59.606 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:59.606 INFO - Command request: select[name=testproject, label=Eden] on session 1bf2070b72af4d41ba413d5d4f568d24
16:02:59.668 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:02.666 INFO - Command request: selectFrame[titlebar, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:02.713 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:07.710 INFO - Command request: click[link=Test Execution, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:07.788 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:10.786 INFO - Command request: selectFrame[relative=up, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:10.849 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:13.847 INFO - Command request: selectFrame[mainframe, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:13.878 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:13.894 INFO - Command request: selectFrame[treeframe, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:13.972 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:16.970 INFO - Command request: selectFrame[relative=up, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:17.001 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:17.001 INFO - Command request: select[//*[@id='settings']/table/tbody/tr[1]/td/select, Production_E2E_Testing_TestPlan] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:17.048 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:17.048 INFO - Command request: waitForPageToLoad[30000, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:20.047 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:20.047 INFO - Command request: select[//*[@id='settings']/table/tbody/tr[2]/td/select, Cycle-14/01/2013 TO 31/01/2013] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:20.109 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:30.103 INFO - Command request: type[//*[@id='filters']/table/tbody/tr[1]/td[2]/input , eden-2532] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:30.134 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:30.150 INFO - Command request: click[//*[@id='doUpdateTree'], ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:30.337 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:30.337 INFO - Command request: waitForPageToLoad[30000, ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:32.555 INFO - Got result: OK on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:32.555 INFO - Command request: click[//img[@class='x-tree-ec-icon x-tree-elbow-plus'], ] on session 1bf2070b72af4d41ba413d5d4f568d24
16:03:32.617 INFO - Got result: ERROR: Element //img[@class='x-tree-ec-icon x-tree-elbow-plus'] not found on session 1bf2070b72af4d41ba413d5d4f568d24
Thread.sleep()
which is a risky anti-pattern in test automation.