动作和htmlunitdriver

编程入门 行业动态 更新时间:2024-10-28 21:18:06
本文介绍了动作和htmlunitdriver-速度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的Web应用程序具有在MouseOver上打开的菜单.我正在使用htmlunitdriver编写测试.

My web application has menus that open on MouseOver. I'm writing tests using htmlunitdriver.

触发菜单的测试代码为

Actions builder = new Actions(driver); WebElement menu = driver.findElement(By.xpath("//a[starts-with(@href,'/index.html')]")); Thread.sleep(2000); builder.moveToElement(menu).build().perform(); Thread.sleep(2000); driver.findElement(By.xpath("//a[starts-with(@href,'/submenuitem')]")).click(); driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);

当我运行一个测试时,它就可以通过了.但是当我尝试一次运行所有80个测试时,我得到了

When I run a single test, it passes just fine. But when I try to run all my 80 tests at once, I get

无法使用//a [starts-with(@href,'/submenuitem'

unable to locate node using //a[starts-with(@href,'/submenuitem'

我猜子菜单尚未打开,htmlunitdriver速度太快. 您可能只与可见元素进行交互,也可能在单次运行中发生.有人可以帮助我解决此问题吗?使用FirefoxDriver大约不是我的选择.

I guess the submenu is not yet open, htmlunitdriver has too much speed. Somethimes a "You may only interact with elements that are visible is occured on single runs too. Can someone help me fix this issue? Using FirefoxDriver or so is not an option for me.

推荐答案

使用手动Thread.sleep(time)等待硒操作是一种肮脏的解决方案,根本不应该使用.

Using a manual Thread.sleep(time) to wait for selenium actions is a dirty solution and should not be used at all.

相反,您可以在与元素进行交互之前检查该元素是否可见.

Instead you could run a check is the element is visible before interacting with it.

public void waitUntilVisible(WebDriver driver, WebElement element){ WebDriverWait waiting = new WebDriverWait(driver, 10); waiting.until(ExpectedConditions.visibilityOf(element)); } public void waitUntilClickable(WebDriver driver, By locator){ WebDriverWait waiting = new WebDriverWait(driver, 10); waiting.until(ExpectedConditions.elementToBeClickable(locator)); } Actions builder = new Actions(driver); WebElement menu = driver.findElement(By.xpath("//a[starts-with(@href,'/index.html')]")); waitUntilVisible(driver, menu); builder.moveToElement(menu).build().perform(); WebElement menuItem = driver.findElement(By.xpath("//a[starts-with(@href,'/submenuitem')]")); waitUntilClickable(driver, By.xpath("//a[starts-with(@href,'/submenuitem')]")); menuItem.click();

更多推荐

动作和htmlunitdriver

本文发布于:2023-11-04 11:31:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557810.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动作   htmlunitdriver

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!