我试图在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"));
}
}
我的测试需要悬停在tooltip上,然后读取并比较值(只有在悬停时才可见值)。悬停时,我的测试似乎根本没有悬停在项目上。在日志中,有信息显示xpath2是错误的(没有元素导致工具提示没有显示。我正在尝试使用本教程中的Action。https:/www.guru99.comkeyboard-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");