替代Chrome中的contextClick:Selenium-WebDriver- Java

时间:2016-01-20 03:41:55

标签: java google-chrome selenium selenium-webdriver selenium-chromedriver

我知道可以找到类似的问题,但没有人给出替代解决方案。请耐心等待。

经过一番研究后,我意识到无法在Chrome浏览器中自动化contextClick。例如:

如果我需要执行以下代码,浏览器必须是Chrome -

driver.get("https://www.google.com");

Actions ac= new Actions(driver);        

ac.moveToElement(driver.findElement(By.id("hplogo"))).contextClick().sendKeys(Keys.ARROW_DOWN).build().perform();

如果我可以选择使用contextClick选项,那将会很有帮助。 感谢

2 个答案:

答案 0 :(得分:0)

在我的Chrome浏览器上,contextClick工作正常。尝试以下代码行,它可以解决您的问题。

ac.moveToElement(driver.findElement(By.id( “hplogo”)))contextClick()的SendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build()执行();

答案 1 :(得分:0)

您是否尝试仅进行上下文点击,然后

    Actions conClick=new Actions(driver);

    //i am expecting you are try to perform right click id = hplogo
    conClick.contextClick(driver.findElement(By.id("hplogo"))).build().perform();

    // if you want to select or click any option in this context menu
    // go for click with specific location, no need of keys
    // if required use sleep before click
    driver.findElement(By.id("required location")).click();

如果在上下文点击之后点击上方没有按预期工作,那么您也可以尝试以下方式

        Actions conClick1=new Actions(driver);
    //i am expecting you are try to perform right click id = hplogo
    //after context click moving to 25 vertically, may be second option in context menu and clicking
    conClick1.contextClick(driver.findElement(By.id("hplogo"))).moveByOffset(5, 25).click().build().perform();

谢谢你, 穆拉利

相关问题