Improved Click Speed on Radio Buttons Using Xpath
I finally decided to tackle a slowness issue which has been slowing my tests forever. It is a simple page with a table of data and corresponding radio buttons which need selected based upon the row I need to use. Here is a screenshot...
In TC I mapped the "Selection_Table" as an object, so I could reference it, and then iterate through the rows to find the correct "Station" value and select the corresponding radio button using a for loop, like this:
function ClickOnCSAInCorrectStation(Station) {
Aliases.browser.SelectionScreen.Selection_Table.Refresh();
let TotalRows = Aliases.browser.SelectionScreen.Selection_Table.ChildCount;
for (let i = 0; i < TotalRows; i++) {
// Log.Message(aqDateTime.Now()); //Time how long iterating rows takes.
if (Aliases.browser.SelectionScreen.Selection_Table.Panel(i).Panel(0).Panel(3).contentText == Station) {
// Log.Message(aqDateTime.Now()); //Time how long the click() action takes.
Aliases.browser.SelectionScreen.Selection_Table.Panel(i).Panel(0).Panel(0).RadioButton(0).Click();
// Log.Message(aqDateTime.Now());
return true;
}
}
}
By uncommenting the timestamps, I found that it took milliseconds for the script to go through each row of the table and find the correct row. However, where I had the problem was when the radio button was actually being clicked, which took an average of 21 seconds! The page and table were fully loaded, no background scripts or anything were running, so I was completely puzzled as to how the actual click could take so long.
So, I decided to instead to try to find the radio button in the row using FindElement instead to perform the click action:
Aliases.browser.SelectionScreen.Selection_Table.Panel(i).FindElement("input").Click();
This resulted in the click now taking 10 seconds average, so it cut the time by a little more than half. But, still too long to click a radio button.
So, finally I decoded to try and go all in finding the radio button using only Xpath as shown here:
Aliases.browser.SelectionScreen.Selection_Table.FindElement("//div[text()='" + Station + "']/parent::*/div/span/span/input").Click();
Much improved, down to 1.5 seconds to click. AND, I was able to eliminate the for loop completely saving a bit more time.
I am posting this because when I was researching I found a handful of posts which referenced the click() method being slow, and a solution wasn't posted that was of help to me. But, if anyone has other suggestions on how to improve the speed of the click even more, then I would be glad to hear them. Doing the above will likely save me an hour of execution time for all my tests combined.