如何在webelement selenium testng上右击? 我给了你doubleclick的例子,同样我需要右键单击方法。请给我最好的一个。
public static void doubleclickOn(String objLocator1){
try
{
findWebElement(objLocator1);
Actions actions = new Actions(driver);
org.openqa.selenium.interactions.Action action = actions.doubleClick(webElement).build();
action.perform();
APP_LOGS.debug("double Clicked on "+locatorDescription);
//System.out.println(locator);
}
catch(Exception e)
{
e.printStackTrace();
APP_LOGS.debug("FAIL : The locator "+locator+" of description "+locatorDescription+": does not exists in webpage:");
Reporting.fail("FAIL : The locator "+locator+" of description "+locatorDescription+": does not exists in webpage:");
}
}
提前致谢
答案 0 :(得分:0)
试试这个: -
假设“ objlocator1 ”由要右键单击的webelement的xpath组成。
public static void rightClickOn(String objLocator1){
try
{
findWebElement(objLocator1);
Actions actions = new Actions(driver);
actions.contextClick(driver.findElement(By.xpath(objLocator1)));
actions.perform();
APP_LOGS.debug("Context Clicked on "+locatorDescription);
//System.out.println(locator);
}
catch(Exception e)
{
e.printStackTrace();
APP_LOGS.debug("FAIL : The locator "+locator+" of description "+locatorDescription+": does not exists in webpage:");
Reporting.fail("FAIL : The locator "+locator+" of description "+locatorDescription+": does not exists in webpage:");
}
答案 1 :(得分:0)
右键单击操作。
也称为上下文点击。
1)下面是使用Actions类演示右键单击操作的代码。
Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
actions.contextClick(elementLocator).perform();
2)从上下文菜单中选择项目
Actions action= new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
action.contextClick(elementLocator).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
//adjust keys.ARROW_DOWN accordingly