简体   繁体   中英

Alternative to contextClick in Chrome: Selenium-WebDriver- Java

I know one can find similar question,but no one gave an alternate solution.Please bear with me.

After some research I realized it is not possible to automate contextClick in Chrome browser.For ex:

If I need to perform below code and browser has to be 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();

It would be helpful if I can get an alternative to using contextClick options. Thanks

On my chrome browser, contextClick is working fine. Try below line of code, it may resolve your problem.

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

Are you trying to do context click only, then

    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();

if above click after context click is not working as expected, then you can also try below way

        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();

Thank You, Murali

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM