Firefox中Selenium Actions二次调用失效问题求助
Firefox下重复调用Actions悬停函数失败的问题
测试时两次调用同一包含Actions操作的函数,首次执行正常且测试用例通过,但第二次在Firefox中无法正确触发悬停动作;程序误判动作已完成,导致后续依赖步骤失败。该代码在Chrome中运行正常,仅在Firefox中异常。
相关代码如下:
private Actions actions = new Actions(driver); @FindBy(css = "div.o-dropdown:nth-child(3)") public WebElement myAccountBtn; public void hoverProfileGoToManageProfiles() { WebElement topNavBar = driver.findElement(By.cssSelector(".c-navbar__container")); wait.until(ExpectedConditions.invisibilityOf(loadingSpinner)); wait.until(ExpectedConditions.elementToBeClickable(topNavBar)); performHoverManageProfiles(); } public void performHoverManageProfiles() { actions.moveToElement(myAccountBtn).perform(); WebElement manageProfilesBtn = driver.findElement(By.xpath("//*[@id=\"app\"]/nav[1]/div/div[2]/div[1]/div[2]/div/a[1]")); WebElement clickableManageProfilesBtn = wait.until(ExpectedConditions.elementToBeClickable(manageProfilesBtn)); clickableManageProfilesBtn.click(); }
注:performHoverManageProfiles()中的manageProfilesBtn需在悬停动作完成后才能找到。
已尝试的方案:
- 将WebElement创建移入函数
- 重置
myAccountBtn - 添加
Thread.sleep() - 增加显式等待
以上方案均未解决问题。
内容的提问来源于stack exchange,提问作者Akaime
相关产品推荐
相关产品推荐

