Code: Select all
bool isPresent = repo.Element1Info.Exists(1000);
if (isPresent)
{
repo.Element1.PressKeys("1");
}
Here is my code (and some of the things I've tried that are commented out):
Code: Select all
public void SetValueWhenPresent(Adapter repoElement, string valueToEnter)
{
bool itemPresent = true;
// Check to see if the item exists
// The following didn't work and failed when passing in an element which didn't exist on the page
try {
Validate.Exists(repoElement, null, false);
} catch(Exception ex) { itemPresent = false;}
// The following didn't work and failed when passing in an element which didn't exist on the page
// try {
// itemPresent = repoElement.Valid;
// } catch(Exception ex) { itemPresent = false;}
// The following didn't work and failed when passing in an element which didn't exist on the page
// itemPresent = repoElement.Valid;
Report.Info("itemPresent = " + itemPresent.ToString());
if (itemPresent)
{
Report.Log(ReportLevel.Info, "Keyboard", "Press keys '" + valueToEnter + "' with focus on '" + repoElement.Element);
repoElement.PressKeys("{Home}{LShiftKey down}{End}{LShiftKey up}{Delete}" + valueToEnter);
}
}
Any suggestions on getting a generic method to do what I'm able to do in the first code snippit (capture the existence of the element and set a max of amount of time to search for it)?
Thanks,
Todd