469,337 Members | 6,157 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,337 developers. It's quick & easy.

trying to find an xpath id using innerHTML

The below code contains 3 buttons Up,Open and Cancel. However theirs id eg div id="ecc_145" are dynamic and change every time I open the application.I'm tring to find the id for the cancel button ,so I can click on it using selenium automation tool.I've included my current(not working ) solution,any ideas??Cheers

[html]<div id="dialog_open_component" class="wc_dialog" caption="Add Product Grid">
<div class="list_container">
<div id="dialog_open_component_list" class="list">
<div class="list_item row_1">
<img class="row_1" align="absmiddle" src="dialogs/images/folder_filled.gif" title="Double click to open folder"/>
<span class="row_1">Foreign Exchange</span>
</div>
<div class="list_item row_0">
</div>
</div>
</div>
<div class="buttons">
<div id="ecc_145" class="Button button_disabled" style="overflow: hidden; position: static; top: 0px; left: 0px; width: 40px; height: 18px; float: left;">Up</div>
<div id="ecc_146" class="Button button_mouseover" style="overflow: hidden; position: static; top: 0px; left: 60px; width: 60px; height: 18px; float: right;">Cancel</div>
<div id="ecc_147" class="Button button" style="overflow: hidden; position: static; top: 0px; left: 140px; width: 60px; height: 18px; float: right;">Open</div>
</div>
</div>
</div>[/html]

My solution.........
[html]var locator="//div[@class='buttons']";var buttonsDiv=selenium.page().findElement(locator); for (var i in buttonsDiv.childNodes){var button =buttonsDiv.childNodes[i]; if(button.innerHTML = 'Cancel');{storedVars["buttonId"]=button.id;};break;}[/html]
Apr 18 '07 #1
1 6579
dorinbogdan
839 Expert 512MB
Welcome to TheScripts TSDN....

I don't have selenium, but it seems that you use javascript code.
Try this updated code:
Expand|Select|Wrap|Line Numbers
  1. var locator="//div[@class='buttons']";
  2. var buttonsDiv=selenium.page().findElement(locator); 
  3. for (var i=0;i<buttonsDiv.childNodes.length;i++){
  4.         var button = buttonsDiv.childNodes[i]; 
  5.         if(button.innerHTML = 'Cancel'){
  6.             storedVars["buttonId"]=button.id;
  7.             break;
  8.         }
  9.     }
  10.  
I'm not sure if the buttonsDiv is correctly filled, if not (it might be an array with one element) try to use:
Expand|Select|Wrap|Line Numbers
  1. var buttonsDiv=selenium.page().findElement(locator)[0]; 
God bless you,
Dorin.
Apr 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Oleg Paraschenko | last post: by
5 posts views Thread by laks | last post: by
2 posts views Thread by yonta via .NET 247 | last post: by
2 posts views Thread by Raed Sawalha | last post: by
1 post views Thread by newToAjax | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.