I am relatively new to the Test Automation and in particular to the Selenium.
I am using Selenium Web-driver, Eclipse.
One of the biggest problems I am experiencing is that our scripts are crashing due to the Internet speed or server performance.
I currently use Thread.sleep()
to solve the problem.
However it is not a secret that Thread.sleep()
enforces waiting time till the timer is completed.
I tried to find an optimised solution in example for the script below.
Having looked through the posts on Stackoverflow I found solution which is provided below in the for(
) loop.
It was suggested to use:
jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete");
to ensure that action (click on the button) is completed, and if not, so to wait a little bit and to try again during the next iteration.
In my case below there would be 6 attempts as per loop.
However the code brings up an error:
"Failure: Cannot invoke "Object.toString()" because the return value of "org.openqa.selenium.JavascriptExecutor.executeScript(String, Object[])" is null"
The code is:
public void SignSupportFormOnOrder() throws InterruptedException {
JavascriptExecutor jse = (JavascriptExecutor)GlobalVariables._browser.currentDriver;
ExplicitWait.until(ExpectedConditions.visibilityOf(Order_SignSupportingForms));
actions.moveToElement(Order_SignSupportingForms).click().perform();
//Code working but using Thread.sleep():
//Thread.sleep(10000); //Need to look for an alternative solution
//jse.executeScript("arguments[0].click();", button_Sign);
/////////////////////////////////////////////////////////////////////////////////////////
//try as alternative to Thread.sleep(...):
for(int i=0; i < 5; i++){
if(jse.executeScript("arguments[0].click();", button_Sign).toString().equalsIgnoreCase("complete"))
break;
else
Thread.sleep(1000);
}
//Thread.sleep(10000);
}
Can somebody kindly give me a suggestion what I am doing wrong and how it would be possible to overcome using Thread.sleep();