How do you pause between actions with Selenium WebDriver

asp.net-mvc-4, selenium, ui-automation

Solution

You can use `pause` between actions

(new Actions(driver))
.clickAndHold(car1)
.moveToElement(car2Tail)
.pause(java.time.Duration.ofSeconds(2))
.release(car1).build()
.perform();

Problem

I've read all of the "why would you want to do that" answers, and the "don't do that, do this" answers. I agree that pausing along the way in automated tests makes no sense unless you are actually waiting for a condition to arrive. That said, there are times I want to 'step through' a list of actions without breakpoints to see the test run smoothly without interruption, during development. Also, stepping through breakpoints sometimes total breaks tests. So here is the scenario: I have hidden menus that show when hovering over them, and then when you hover over the now-visible options they are highlighted by changing their background colors as the mouse moves from one to another; common menu scenario. I want to automate that very thing and be able to see it work WHILE I'M DEVELOPING IT, and then throw that part away when I like what I see. Pardon me, I'm not shouting, just emphasizing. So I get the top element of the menu, then the list of options to chose from. Then hover over each of the first 3 options in order. ``` var element = page.WebDriver.FindElement(By.Id("actions")); var elementLi = element.FindElements(By.TagName("li")); Actions action = new Actions(page.WebDriver); action.MoveToElement(element).Perform(); action.MoveToElement(elementLi[1]).Build().Perform(); action.MoveToElement(elementLi[2]).Build().Perform(); action.MoveToElement(elementLi[3]).Build().Perform(); ``` Yes I can set breakpoints, but if I put implicit waits, or Thread.Sleep(5000) in between each of the MoveToElement calls there is no pause. I.E., it runs through lickity-split without so much as a wink at me for good-neighborliness. This is hardly a critical issue, I agree. But why does nothing work to pause between?

Original source