Reputation: 136
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
Upvotes: 0
Views: 818
Reputation: 3927
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
Upvotes: 0
Reputation: 51
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();
Upvotes: 0