Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting context menu options #1575

Closed
bittlingmayer opened this issue Dec 11, 2017 · 15 comments
Closed

Selecting context menu options #1575

bittlingmayer opened this issue Dec 11, 2017 · 15 comments
Labels

Comments

@bittlingmayer
Copy link

It seems that context menu is a native element and outside of the document, and thus belongs in Page, similar to screenshot functionality and so on.

It can be hacked with keydown events and keyboard events or maybe even selectors, and that's how it is in Selenium, but that's not ideal.

@ebidel
Copy link
Contributor

ebidel commented Dec 11, 2017

Indeed. This is similar to #1306. Context menus live outside the browser, at the OS level.

AFAIK, there's no way to interact with context menus from a page, other than the contextmenu event. We can't do much in the Puppeteer-space to make this work.

@bittlingmayer
Copy link
Author

Chrome Extensions support adding and removing items to and from the context menu so it seems that the browser has some hooks.

@bittlingmayer
Copy link
Author

Is there a recommended way to do this for now?

The context menu opens on right click but, at least on MacOS, keyboard.press('ArrowDown') does not work. (If I actually press the down arrow it does work.) Same for other ways to navigate the menu like typing letters.

@ebidel
Copy link
Contributor

ebidel commented Dec 13, 2017

Right, all of those interactions are at the OS level. Meaning they live outside the browser/puppeteer space. There's no workaround AFAIK.

Do other automation frameworks support similar features?

@bittlingmayer
Copy link
Author

bittlingmayer commented Dec 14, 2017

Do other automation frameworks support similar features?

No and yes.

Not in any first-class way. You probably know better than I do. With Selenium it's possible to navigate the opened context menu with the arrow keys (most common from what I see) or to type to effectively "find" by text (less brittle in my opinion).

(I'm more or less trying to port code I wrote in Python with Selenium to Node with Puppeteer, but right now it seems I will have to use Node with Selenium.)

But those that come to mind are third-party tools supporting multiple browsers (and multiple programming languages...), not an official tool living in a repo of one browser.

If supporting automated testing of Extensions is a goal then it seems natural to provide a bit more context menu support.

@ebidel
Copy link
Contributor

ebidel commented Dec 14, 2017

If supporting automated testing of Extensions is a goal then it seems natural to provide a bit more context menu support.

Headless chrome does not support extensions #1215 (comment)

@aslushnikov
Copy link
Contributor

Closing this since it seems there's not much interest in context menus. We can always revisit this later.

@VikramTiwari
Copy link
Contributor

Hey @bittlingmayer were you able to make this work?

@bittlingmayer
Copy link
Author

@VikramTiwari No, I dropped Puppeteer and just used Selenium, and did what I needed to do with flags to Chrome.

@avalanche1
Copy link

I'm developing an extension that uses context menus extensively. I would like puppeteer to support context menu testing.

@tommydamiano
Copy link

was this ever solved? having the same problem selecting from context menus on mac

@a-y-u-s-h
Copy link

Reopen this please.

@IgnacioYanjari
Copy link

@avalanche1 what is the extension's name? did u finish that extension? I really need a best approach instead of using only arrow keys to navigate through options

@avalanche1
Copy link

@IgnacioYanjari I'm not sure what you're asking. DM me on instagram @mister.kat.il.magnifico, I'll try to help

@verhovsky
Copy link

It can be hacked with keydown events and keyboard events

Can it? I'm trying to implement "open in new tab" on macOS by doing just that

    await page.click('a', { button: "right" }); // right click the first <a></a> element
    await page.waitForTimeout(1000);
    await page.keyboard.press('ArrowDown');  // move to the first item in the context menu
    await page.waitForTimeout(1000);
    await page.keyboard.press('Enter'); // open the first item
    await page.waitForTimeout(1000);

but it has same effect as left-clicking the link. It opens the link in the current tab instead of a new tab. I suspect .click() causes the element to be highlighted and then .press('Enter') presses Enter on the highlighted element. It doesn't select the first option in the context menu (which is normally "Open Link in New Tab" when right clicking on links) like I wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants