Costantino Grasso
Costantino Grasso

Reputation: 33

Select option from context click menu in Chrome

I'm facing an issue in Chrome 47, using Selenium (WebDriver) 2.48.2, ChromeDriver 2.20.353145, and Java as programming language. I couldn't find any solutions online. I need to open the "right click menu of browser" (or context click menu) from an input and I could do this using this code:

new Actions(driverExample).contextClick(inputExample).build().perform();

So the next step: select an option from it. I searched online and it seemed simple, but it's not. I didn't try on others browsers, but I always saw online that many people did this in Firefox and Internet Explorer using something like:

new Actions(driverExample).contextClick(inputExample).sendKeys(Keys.ARROW_UP).sendKeys(Keys.ARROW_UP).sendKeys(Keys.RETURN).build().perform();

In this situation I put two "arrow up" and one "enter", because I have to select the second option from the bottom. Anyway, this seems to work for people in Firefox and Internet Explorer, but not on Chrome and I also saw few discussions about this problem without solution. So why not give to me and the others a final solution here? Thanks in advance.

Upvotes: 0

Views: 2461

Answers (1)

srees
srees

Reputation: 296

Seems an issue. It is working with firefox but not with chromedriver. Please raise issue at https://bugs.chromium.org/p/chromedriver/issues/list

Sample Code:

WebDriver driver = new ChromeDriver();      
driver.get("http://www.google.com/");
Actions a = new Actions(driver);

WebElement input = driver.findElement(By.name("q"));
input.sendKeys("test");
a.contextClick(input).sendKeys(Keys.chord(Keys.ARROW_UP,Keys.ARROW_UP,Keys.ARROW_UP,Keys.ARROW_UP,Keys.ENTER)).build().perform();

Upvotes: 1

Related Questions