ATag.click losing focus
Posted: Thu Mar 12, 2009 7:56 pm
Sometimes (about 1 in 5 attempts) ATag.click is not actually clicking the link I tell it to. Instead it is causing the web browser to lose focus and (seemingly) randomly clicking somewhere else on the desktop. Please see the following code:
With the above code I get through the first Try/Catch where I am verifying the link exists on the page. Then it gets to the "Click a Link" section where I get in my report that the link was click. That means as far as Ranorex is concerned the link was clicked (there was no exception thrown). However, a small % of time the link was in fact NOT clicked and my web browser no longer has focus. Obviously this has a detrimental effect on the rest of my code that is expecting that the link was clicked since this function is returning that everything is happy.
Can you take a look at my code and/or the ATag.Click code to see if there is something there you can think of as to why I am losing focus of the web browser and the link is not clicked?
Thanks...
Code: Select all
private static int DOMClickLink(Ranorex.WebDocument webDocumentName, string LinkText)
Ranorex.ATag DOMlink;
//Search for the Link on the page
try
{
webDocumentName.EnsureVisible();
Thread.Sleep(500);
DOMlink = webDocumentName.FindSingle(".//a[@innertext='" + LinkText + "']");
}
catch (RanorexException e)
{
Report.Error("Unable to find Link: " + LinkText);
Report.Screenshot();
Console.WriteLine("Unable to find Link: " + LinkText);
return -1;
}
//Click a Link
try
{
Report.Info("Clicking Link: " + LinkText);
DOMlink.Focus();
Thread.Sleep(500);
DOMlink.Click(Location.Center);
Report.Debug(" Clicked Link: " + LinkText);
}
catch (RanorexException e)
{
Report.Error(e.ToString());
Report.Screenshot();
Console.WriteLine(e.ToString());
return -1;
}
return 0;
} //End DOMClickLink
Can you take a look at my code and/or the ATag.Click code to see if there is something there you can think of as to why I am losing focus of the web browser and the link is not clicked?
Thanks...