trying to find an xpath id using innerHTML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gordonconroy
    New Member
    • Apr 2007
    • 1

    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_dialo g" caption="Add Product Grid">
    <div class="list_con tainer">
    <div id="dialog_open _component_list " class="list">
    <div class="list_ite m row_1">
    <img class="row_1" align="absmiddl e" src="dialogs/images/folder_filled.g if" title="Double click to open folder"/>
    <span class="row_1">F oreign Exchange</span>
    </div>
    <div class="list_ite m 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_mouseove r" 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=sele nium.page().fin dElement(locato r); for (var i in buttonsDiv.chil dNodes){var button =buttonsDiv.chi ldNodes[i]; if(button.inner HTML = 'Cancel');{stor edVars["buttonId"]=button.id;};br eak;}[/html]
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    Welcome to TheScripts TSDN....

    I don't have selenium, but it seems that you use javascript code.
    Try this updated code:
    Code:
    var locator="//div[@class='buttons']";
    var buttonsDiv=selenium.page().findElement(locator); 
    for (var i=0;i<buttonsDiv.childNodes.length;i++){
    		var button = buttonsDiv.childNodes[i]; 
    		if(button.innerHTML = 'Cancel'){
    			storedVars["buttonId"]=button.id;
    			break;
    		}
    	}
    I'm not sure if the buttonsDiv is correctly filled, if not (it might be an array with one element) try to use:
    Code:
    var buttonsDiv=selenium.page().findElement(locator)[0];
    God bless you,
    Dorin.

    Comment

    Working...