简体   繁体   中英

How to keep dropdown open on mouse over using webdriver

I have the below code:

WebElement we = driver.findElement(By.className("status"));
WebElement we1 = driver.findElement(By.id("7oSL5I7egLSgqmGVYpF_lG6VyY3ZR7SArK6pYZVU3g"));

Actions builder = new Actions(driver);
builder.moveToElement(we).build().perform();
builder.moveToElement(we1).build().perform();
we1.click();

Here I am performing a mousehover on the we element which is performing fine but I can't keep the dropdown we open for further selection of we1 (a checkbox)

Generally I would expect an actions chain to be joined together like this:

builder.moveToElement(we).moveToElement(we1).click().perform();

This should then perform all required actions in the chain without pause and without losing hover focus. The other option of course is to break this into two distinct actions like so:

WebDriverWait wait = new WebDriverWait(driver, 15, 100);

builder.moveToElement(we).perform();
waiting.until(ExpectedConditions.visibiltiyOf(we1));
builder.moveToElement(we1).click().perform();

The explicit wait is used to ensure that the element "we1" is visible before trying to hover over and click on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM