java - Selenium Java Provar - 为什么我的动作 moveToElement 不执行
问题描述
我正在尝试在 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 错误的信息(没有元素导致工具提示未显示。我正在尝试使用本教程中的操作: https ://www.guru99.com/keyboard-mouse-events-文件-webdriver.html
PS 我的 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");
推荐阅读
- vim - Unable to get out of terminal window inside VIM using VIM key bindings
- jquery - Radio input section toggle with jQuery
- sql - SUM FIRST_VALUE 或 SUM group by 同时仍显示所有行?
- python - Windows 10 python.exe neither runs nor gives error in command line
- c# - 连接到在另一台计算机上作为 Windows 服务运行的 WCF
- c++ - 请求最简单的 OpenMP 目标 GPU 示例
- javascript - Javascript暂停/等待;同步执行
- vue.js - 如何绑定插入到 vuejs 中的 v-html 的链接中的数据?
- python - discord.py 文本到语音模块?
- java - 加快处理大文件的方法