Selenium Java Provar - 为什么我的动作 moveToElement 不执行

Selenium Java Provar - Why my action moveToElement does not perform

我正在尝试在 Provar 中使用 Selnium Java 执行 moveToElement 操作。 我的操作导入:

import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

我的自定义方法是:

        public void checkContractNumberOnHover() {
        WebDriver driver = provarSeleniumDriver.getWebDriver();
        Actions builder = new Actions(driver);

        WebElement contract = driver.findElement(By.xpath("MyXpath1"));
        WebElement contractProperNumber = driver.findElement(By.xpath("MyXpath2"));

        Action mouseOverContract = builder.moveToElement(contract).build();
        mouseOverContract.perform();
value");

        assertTrue(contractProperNumber.isDisplayed());

        String contractActualString = contractProperNumber.getText();
        assertTrue(contractActualString.contains("N2019-0001"));        
    }
}

我的测试需要将鼠标悬停在工具提示上并读取然后比较值(值仅在悬停时可见)。悬停似乎我的测试甚至没有悬停在第一位的项目上。在日志中有 xpath2 错误的信息(没有元素导致工具提示未显示。我正在尝试像本教程中那样使用 Action: https://www.guru99.com/keyboard-mouse-events-files-webdriver.html

P.S 我的 xpaths ok 测试了多次,每个元素都找到了一个元素。我不知道为什么 moveToElemnt 操作甚至不触发 :(

将 xpath 的每个发现放入 Try -catch--see。如果未找到元素也将用于 xpath1

Actions actions = new Actions(driver);
try{
  WebElement contract = driver.findElement(By.xpath("MyXpath1"));
}
catch(Exception e)
{
syso("print exception"+e.getmessage);
}

WebElement contractProperNumber = driver.findElement(By.xpath("MyXpath2"));
actions.moveToElement(contract).`enter code here`perform();
System.out.println("Done Mouse hover on xpath1");