Forum Discussion

tayssire's avatar
tayssire
Occasional Contributor
12 years ago

Find an object inside an HTML page failed

I have this HTML page named Test.html 



<HTML>

<BODY>

<TD id=id512 title="The currency against which the spot rates are quoted and through which the cross rates are calculated." class=label>Reference: </TD>

<TD id=InRefCurrencyCombo><QC:comboQC id=RefCurrency CALLBACK="HideTabRef" INPUT_SIZE="1" TYPE="MODEL" SOURCE_NAME="OutRefCcyList" INPUT_NAME="InRefCurrency"><SPAN class="output overridable"><SPAN class=wrapper><INPUT tabIndex=0 id=RefCurrency_combo title="" class=comboInput readOnly size=1 value=USD quicktestproid="InRefCurrency-OutRefCcyList"><SPAN id=RefCurrency_comboButton class=comboButton></SPAN></SPAN></SPAN></QC:comboQC></TD>

<TD id=id518 title="Activate to enable extrapolation for out of bounds values." class=label>Extrapolation: </TD>

<TD id=id521><QC:comboQC tabIndex=-1 id=AllowExtrapolation INPUT_SIZE="16" TYPE="XML" SOURCE_NAME="xml_AllowExtrapolation" INPUT_NAME="InAllowExtrapolation"><SPAN class="output overridable"><SPAN class=wrapper><INPUT tabIndex=-1 id=AllowExtrapolation_combo title="" class=comboInput readOnly size=16 value=No quicktestproid="InAllowExtrapolation"><SPAN id=AllowExtrapolation_comboButton class=comboButton></SPAN></SPAN></SPAN></QC:comboQC></TD>

<TD id=ODVlabelId title="Calculate one-day values" class=visible>


<DIV id=3BE32594-9771-4305-8BFD-6D90F704F96B style="HEIGHT: 0px; POSITION: absolute; LEFT: -1000px; TOP: -10000px; WIDTH: 1%">

<TABLE id=2DF3CE9F-9418-4972-8816-E832C5A3E253 class="dropdownCalc dropdown" cellSpacing=0 cellPadding=0>

<TBODY>

<TR>

<TD class=dropdownTop></TD>

<TD class=dropdownTopRight><SPAN></SPAN></TD></TR>

<TR>

<TD class=dropdownContent colSpan=2>

<DIV>

<TABLE id=AC67655C-39ED-4db9-9A69-A76F7AD3F3FA cellSpacing=0 cellPadding=0>

<TBODY>

<TR>

<TD><SPAN>Incl. Ref. CCY</SPAN></TD></TR>

<TR>

<TD><SPAN>Cross CCY Only</SPAN></TD></TR></TBODY></TABLE></DIV></TD></TR>

<TR>

<TD class=dropdownBottom></TD>

<TD class=dropdownBottomRight><SPAN></SPAN>

</TD></TR></TBODY></TABLE></DIV>

</BODY></HTML>





I m searching for the Table Object with this Id  id=AC67655C-39ED-4db9-9A69-A76F7AD3F3FA



I used a piece of code that i found on your help :

the html page is well loaded into chrome the problem is on the Find object in debug mode i have a clear message that the object doesnt exist .





function testdrop()

{

var url = "file:///C:/Users/user/Desktop/test.html";

// Using Find

Browsers.Item(btChrome).Run(url);

var page = Sys.Browser("chrome").Page(url);

// Using the Find method

var table = page.NativeWebObject.Find("idStr", "AC67655C-39ED-4db9-9A69-A76F7AD3F3FA



");

// Checks if the button exists

if (table.Exists)

  log.message("the object has been found")

else

 log.message ("the object is not found ")

}



would you know what i need to change to have it works

thanks a lot

Tayssir .


1 Reply


  • Hi Tayssir,


     


    As you want to get the object by its HTML tag, I would suggest that you use the EvaluateXPath method.


    In this case, the script will look like this:



     


    function Test()


    {


      ...


      var page = Sys.Browser("*").Page("*");


     


      var tmp = page.EvaluateXPath("//TABLE[@id='AC67655C-39ED-4db9-9A69-A76F7AD3F3FA']");


      if (tmp != null)


      {


        // If the element was found,


        // convert the array to the JScript-compatible format


        var arr = (new VBArray(tmp)).toArray();


        // and simulate a click


        arr[0].Click(); // Note we refer to the array item


      }


      else


      { 


        // If the element was not found, post a message to the log


        Log.Error("The element was not found.");


      }


    }