It's pretty frustrating. Everywhere I look people keep telling me to use explicit, implicit, and fluent waits. These waits make it so you pause based on elements. However, patronizing us and removing tools and options is not a good idea. In my current specific pickle, I have a button that is designed to disappear if someone clicks on it too quickly. However, it is also designed to now show up immediately either. So you have to wait until it shows up, then wait for enough time to pass by, and only then click the button. With the suggestions, I am given it is impossible. A static pause or sleep has to be used in this case. For some reason, I can't even use thread sleep because it seems like it has been deprecated in Java 8 itself or something.

- 183,867
- 41
- 278
- 352

- 161
- 1
- 2
- 11
-
1Does anything changes in the html between the button appearance and the button being eligible for click? and why do you think `Thrrad.sleep()` is deprecated in Java 8? – Guy Mar 31 '19 at 11:51
-
I would suggest an explicit wait to wait for the button to appear, then a Thread.sleep to wait for the the minimal amount of time needed to ensure the it has not been clicked too quickly and does not disappear in this specific scenario – Ardesco Apr 03 '19 at 10:10
-
Also Java 8 docs for Thread.sleep (it's not deprecated) https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#sleep-long- Would be good to have more details of the error you are seeing, to help you with the Thread.sleep part of the problem – Ardesco Apr 03 '19 at 10:11
3 Answers
implicit Wait:
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
Explicit Wait:
WebDriverWait wait = new WebDriverWait(WebDriverRefrence,TimeOut);

- 5,031
- 17
- 33
- 41

- 9
- 3
What's the source that makes you think, that java.lang.Thread would be deprecated?
So even in the Java 11 docs it is not deprecated.
So if you want to use it, feel free. :-)

- 2,466
- 1
- 19
- 25
-
I can't seem to make the command stop erroring no matter what imports i use. – sergiy Mar 31 '19 at 11:58
-
Please show the imports you are using and the corresponding error messages and deprecation warnings. – mle Mar 31 '19 at 14:15
Possibly through the terms static wait and static pause you meant Thread.sleep()
which is still useful in many ways.
However, while executing your Tests through Selenium inducing sleep wouldn't be an elegant solution to fix the issue as inducing Thread.sleep(1000);
degrades the overall Test Execution Performance. You can find a detailed discussion in Selenium needs a sleep before going to the next page.
If you need to induce waits Implicit Waits is a good way to start with. You can find a detailed discussion in Using implicit wait in selenium. However as the current Web Applications are built through JavaScript, Angular, ReactJS, etc Explicit Waits would be the way forward.
So, moving forward you can make a transition towards Explicit Waits. You can find a detailed discussion in Replace implicit wait with explicit wait (selenium webdriver & java).
At this point, implementing Fluent Wait will be much easier and you can find a detailed discussion in Implicit vs Explicit vs Fluent Wait.

- 183,867
- 41
- 278
- 352
-
2Using `Thread.sleep()` to wait for elements, etc. is not a good practice but if you need to time something specific on the page as OP is, it's fine to use. Using implicit waits is NOT a best practice per the Selenium contributors, as I've mentioned before. Explicit waits and Fluent waits are basically the same, Explicit waits are just prepackaged waits and both are "best practice" waits. – JeffC Apr 01 '19 at 21:59
-
+1 never use implicit waits, always use explicit ones (explicit waits are built on top of fluent waits, I agree they are the same thing for all intents and purposes. A fluent wait is just an explicit wait with some additional config options) – Ardesco Apr 03 '19 at 10:08