Frage

What is the difference between Thread.Sleep() and selenium.setSpeed("2000")?

War es hilfreich?

Lösung

setSpeed : Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation). By default, there is no such delay, i.e., the delay is 0 milliseconds.

Thread.sleep : It causes the current thread to suspend execution for a specified period.

So the main difference between them is setSpeed sets a speed while will apply delay time before every selenium operation takes place. But one thread.sleep() will set up wait only for once. So, if we have 3 selenium operations written like below:

Opeartion 1
Opeartion 2
Opeartion 3

and we want to set a delay time 2000 for each of these, defining setSpeed() method once will accomplish the task something like below:

selenium.setSpeed("2000");
Opeartion 1
Opeartion 2
Opeartion 3

But if we use Thread.sleep(), it will be something like below:

Thread.sleep(2000);
Opeartion 1
Thread.sleep(2000);
Opeartion 2
Thread.sleep(2000);
Opeartion 3

Andere Tipps

Thread.sleep() will stop the current (java) thread for the specified amount of time. It's done only once.

Selenium.setSpeed() will stop the execution for the specified amount of time for every selenium command. It is useful for demonstration purpose (you will see thing moving in your browser) or if you are using a slow web application (there are better technique to handle slow applications but that's off topic.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top