How to write the code in selenium to wait for each action happened in the class. Basically it happened very fast we can't see any action while executing.Lets say an example if i click on button should wait for 2 seconds and after loading page should wait wait for 2 seconds mean need to wait for each action i should be able to see each action in detail. I can write Thread.sleep(); but for each action i need to write this. I want to write once like implicit wait() or explicit wait(). Any suggestions will be greatly appreciated.
Asked
Active
Viewed 623 times
0
-
Simple. Keep Thread.Sleep(2000L); or else use implicit wait http://www.guru99.com/implicit-explicit-waits-selenium.html – Kishan Patel Mar 01 '17 at 09:39
-
1Except thread.sleep(); Implicit only wait until element found. i want to wait for some time in between actions. – sandeep kumar Mar 01 '17 at 09:43
-
I have shared the link . Please see the link , there are n number of waits which you can apply. – Kishan Patel Mar 01 '17 at 09:53
-
3@KishanPatel It's possible that the waiting features Selenium offers don't include what the OP wants (I didn't see one but I just gave a quick look). Regardless, OP, if you are not happy with the waiting features Selenium offers, of course you have the option of wrapping the Selenium actions in methods of yours, where you do the wait (`Thread.sleep`) yourself before the action. F.ex. you could write your own `click` method and in it you just wait and then click. Then you always call that method instead of Selenium's `click`. – SantiBailors Mar 01 '17 at 10:01
-
I saw it none of them works for this scenario.Thanks. – sandeep kumar Mar 01 '17 at 10:01
-
Can u suggest me with the method if possible @SantiBailors – sandeep kumar Mar 01 '17 at 10:03
-
I don't have time to write an example right now, maybe in a few hours. But it's quite trivial, you should try yourself. – SantiBailors Mar 01 '17 at 10:08
-
I appreciate it @SantiBailors Thanks :) – sandeep kumar Mar 01 '17 at 10:15
-
You are welcome, but you have no guarantee that I or someone else will do that. That's not how Stack Overflow works. So don't be passive, especially in front of such trivial coding. Try to do it yourself, and if you get stuck with doubts or errors explain them. – SantiBailors Mar 01 '17 at 10:24
-
@sandeepkumar Try this, `selenium.setSpeed("2000")` it is going to slow down the speed of execution. – Gaurang Shah Mar 01 '17 at 11:54
-
@GaurangShah You don't say what class the `selenium` in your example is, and I couldn't find that `setSpeed` method in the Selenium 3.0.1 classes I looked at. According to [this answer](http://stackoverflow.com/a/11158493/2814308) from a Selenium contributor, that method is long gone. – SantiBailors Mar 01 '17 at 12:49
-
OP, see [this answer](http://stackoverflow.com/a/32068026/2814308), it shows examples of helper methods for the actions you want to make wait. It also shows code for the alternative solution of overriding the existing methods to just add a wait before the action. Personally I prefer the latter approach. Regardless, here is a link with info that would certainly interest you if you want a more Selenium-friendly solution: [FluentWait](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html). – SantiBailors Mar 01 '17 at 13:46