Lately I have written the following code to click on any of the following elements which is visible:
Purpose : It is basically a never ending loop to repeat the same action again i.e, click 3 buttons.
Problem : When I run the code it seems to take arbitrary time between 1 second- 7 seconds to click a button, tough page gets loaded successfully in an instant. Hence I am eager to know what is it in the code which the delaying the operation? and Is there any efficient way to reduce the time?
battle(WebDriver driver1)
{
try { if(driver1.findElements(By.xpath("....")).size()!= 0)
{
driver1.findElement(By.xpath("....")).click();
}
if(driver1.findElements(By.xpath("....")).size()!= 0)
{
driver1.findElement(By.xpath("....")).click();
}
if(driver1.findElements(By.xpath("....")).size()!= 0)
{
driver1.findElement(By.xpath("....")).click();
}
battle(driver1);
}
catch(Exception e)
{
battle(driver1);
}
}