Page 1 of 1
finding elements
Posted: Thu Jun 24, 2010 9:20 pm
by tony1212
having trouble getting used to the layout with this tool maybe someone can give me some pointers.
I have a website. lots of my code will need to submit form data (which is easy enough) then go through tables and validate that values are correct (html tables, data grids....)
I was hoping the spy tool let me hover over a dom element get its name and use that in my script something like (providing these names had meaning)
table_itable.cell3.getText(); or table_itable.cell3.setText();
ideally if there was a generic (and maybe there is) find() command that I can take an element name and do a find on it then use it
(assume X is a valid object type)
X = find(itable.cell3);
X.getText(); or X.setText();
then I don't need a static map that needs to be maintained.
Did any of that make sense and if so can Ranorex do anything similar.
Re: finding elements
Posted: Thu Jun 24, 2010 9:50 pm
by Ciege
Sounds like you need to start reading about FindSingle. For what it's worth, I don't use a repository map either.
What I do is create a framework of useful / reusable methods that do work for all of my automation scripts. In this framework I crate methods such as
DOMTextBoxClick and
DOMCheckBoxClick etc. Then from my automation script I call the method and pass it the object name I am looking for.
As an example here is the
DOMTextBoxClick method:
Code: Select all
public static int DOMTextBoxClick(Ranorex.WebDocument webDocumentName, string TextBoxName)
{
/************************************************************************
* Function : DOMTextBoxClick(Ranorex.WebDocument webDocumentName, string TextBoxName)
*
* Description : This function will click a text box in a web document.
*
* Parameters : webDocumentName - The web DOM object the the TextBox lives on
* : TextBoxName - Name of the TextBox to click
*
* Return Type : Integer
*
* Return Value : 0 for success, -1 for failure
*
* Revision History
* Date : Author : Reason/Change
* ---------- : ------------------------- : ------------------------------
* 03/09/2009 : Chris Gendreau : Initial Creation
************************************************************************/
Ranorex.InputTag DOMTextBox;
//Search for the TextBox on the page
try
{
webDocumentName.EnsureVisible();
Thread.Sleep(500);
DOMTextBox = webDocumentName.FindSingle(".//input[@Id='" + TextBoxName + "']");
}
catch (RanorexException e)
{
Report.Error("Unable to find TextBox: " + TextBoxName);
Report.Error(e.ToString());
Report.Screenshot();
return -1;
}
//Ranorex Debug
Report.Debug("DOM ScreenRectangle: " + webDocumentName.ScreenRectangle.ToString());
Report.Debug("DOM Valid: " + webDocumentName.Valid.ToString());
Report.Debug("InputTag ScreenRectangle: " + DOMTextBox.ScreenRectangle.ToString());
Report.Debug("InputTag Valid: " + DOMTextBox.Valid.ToString());
//Click a TextBox
try
{
Report.Info("Clicking TextBox: " + TextBoxName);
//DOMTextBox.EnsureVisible();
DOMTextBox.Focus();
Thread.Sleep(1000);
DOMTextBox.Click(Location.Center, 1000);
//DOMTextBox.PerformClick();
Report.Debug(" Clicked TextBox: " + TextBoxName);
}
catch (RanorexException e)
{
Report.Error(e.ToString());
Report.Screenshot();
return -1;
}
return 0;
} //End DOMTextBoxClick
Re: finding elements
Posted: Thu Jun 24, 2010 10:02 pm
by tony1212
thanks for the reply and yes I admit posting this was a bit lazy as I am new to the tool and have not done all my homework.
thanks