How do you pause between actions with Selenium WebDriver

I read all the answers "why do you need to do this", and the answers "do not do this, do this." I agree that a pause in the way in automated tests does not make sense if you do not really expect the condition to arrive.

However, there are times when I want to "step over" the list of actions without breakpoints to see the test run without interruptions during development. In addition, step-by-step control points sometimes pass tensile tests. So, here is the scenario: I have hidden menus that show when they are poking over them, and then when you hover over the now visible parameters, they are highlighted by changing their background colors when the mouse moves from one to the other; general menu script. I want to automate this and see how it works while I DEVELOP IT, and then throw this part away when I like what I see. Forgive me, I'm not screaming, just emphasizing.

So, I get the top menu item, and then a list of options to choose 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();

, Thread.Sleep(5000) MoveToElement, . .., , , .

, . ?

+4
4

FluentWait, WebDriverWait, . . waitForElementToAppear( By locator ), .

0

Java WebDriver $Timeouts.class - implicitlyWait (long time, TimeUnit unit).

webdriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

, , .

, -, . , .

0

, -, , -, , , FluentWait, WebDriverWait ( ), , , , TimeoutException.

-

try {
    WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds, sleepInMilliseconds);
    wait.until(Predicates.<WebDriver> alwaysFalse());
}
catch(TimeoutException e) {
    //Ignore the timeout.  It what we *want* to happen.
}

using overload WebDriverWait untilthat uses the guava predicate.

You want to minimize state polls with the appropriate choice of the wait period.

0
source

You can use pausebetween actions

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

Source: https://habr.com/ru/post/1541187/


All Articles