我在这里找到了这段代码:https://stackoverflow.com/a/22376627/4165083
Actions oAction = new Actions(driver);
oAction.moveToElement(Webelement);
oAction.contextClick(Webelement).build().perform(); /* this will perform right click */
WebElement elementOpen = driver.findElement(By.linkText("Open")); /*This will select menu after right click */
elementOpen.click();
但我遇到驱动程序问题:“无法解析符号驱动程序”。我无法导入任何东西。我应该怎么做才能让它在我的Scala测试中工作?
答案 0 :(得分:1)
我相信你引用了错误的元素。您必须引用您尝试右键单击的元素;
WebElement elementToRightClickOn = driver.findElement(By.id("something"));
Actions oAction = new Actions(driver);
oAction.moveToElement(elementToRightClickOn);
oAction.contextClick(elementToRightClickOn).build().perform(); /* this will perform right click */
WebElement elementOpen = driver.findElement(By.linkText("Open")); /*This will select menu after right click */
elementOpen.click();
答案 1 :(得分:0)
“无法解析符号驱动程序” - 检查是否已创建WebDriver实例并且可以访问。
对于Actions类 - 导入org.openqa.selenium.interactions.Actions; 提供完整的代码以协助。