Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
6.6k views
by
retagged by
In selenium webdriver script, i want to reduce the execution speed of selenium webdriver in java.

I searched in lot of sites. But i didn't get the solution for this.

1 Answer

1 like 0 dislike
by Master (1.2k points)

Basically, you would want to reduce a speed of Selenium WebDriver to make sure that your script does not fail as the element does not appear or takes time to appear. You can mostly do this by implementing Implicit Wait or Explicit wait.

Implicit Wait:

An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The implicit wait is set for the life of the WebDriver object instance. driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Explicit Wait: 

It is more extendible in the means that you can set it up to wait for any condition you might like. Usually, you can use some of the prebuilt ExpectedConditions to wait for elements to become clickable, visible, invisible, etc

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

Here you can wait for an element explicitly to appear or be clickable first then do an operation on it.

Say, you have a contact form which asks name and email address and when you click submit button, it simply submits the form and shows the thank you message. The submission happens through AJAX call, so you will know see whole page loading.

For such scenarios, you can use Explicit Wait to wait for the Thank you message to appear after you press/click submit button.

Hope that helps!

by Contributing Tester (78 points)
Thank you sir providing the solution.Already i tried explicit wait, it will wait until the expected condition is true within the specific time(20).
WebDriverWait wait=new WebDriverWait(driver, 20);
For Example
I have 10 lines of code which contains like entering the text and click.I want to maintain some gap commonly in between each lines(comments).
by Master (1.2k points)
In that case, the ideal way is to use

Thread.sleep(1000); //Its 1000 milliseconds. So 1 second wait time.
by Contributing Tester (78 points)
Thank you sir spending your valuable time to respond this comment. Generally, Thread.sleep(1000) is not good practice is right.Actually my problem is , When i run the script, its executed very fast. So i can't view properly what is happened.
by Master (1.2k points)
Agreed! If you want to see the execution flow, you can simply add a debug point at the starting of your test or wherever you want and debug your code to see step by step execution.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...