我正在使用Provar中的Selnium执行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
对我的xpath进行多次测试,为每个元素找到一个元素。我不知道为什么moveToElemnt操作甚至不触发:
发布于 2020-05-26 02:01:11
将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");
https://stackoverflow.com/questions/62018653
复制相似问题