0

I would like to use ActionChains function of Selenium. Below is like my codes. But It does not work when it opens right click menu. The ARROW_DOWN and ENTER are implemented in main window not, right click menu. How can the ARROW_DOWN and ENTER code be implemented in right click menu.

Brower = webdriver.Chrome()

actionChain = ActionChains(Browser) actionChain.context_click(myselect[0]).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()

Coder
  • 1
  • 1
  • What is your goal? Are you trying to test a web application? Are you trying to automate some personal task? Or something else? – Ian Lesperance Mar 02 '18 at 13:56
  • I try to automate my personal task. My goal is to download the link file. But the file is opened in the web not downloaded. Is there other way to download linked file? – Coder Mar 06 '18 at 01:41
  • To find an answer that address native context menus, see: https://stackoverflow.com/a/59361853/1747771 – Tom Nov 11 '20 at 01:55

2 Answers2

1

Selenium cannot see or interact with native context menus.

Ian Lesperance
  • 4,961
  • 1
  • 26
  • 28
  • 1
    what is the purpose of `actions.context_click().perform()` existing then? I have been searching for the solution to this an find it astounding such a solution does not exist or isn't documented for python – Rhys Dec 20 '18 at 23:05
  • @Rhys, it appears that the context_click exists for context menus that offer app-specific functionality (e.g., right-clicking on a youtube video offers an app-specific context menu), but not for the browser's generic context menu. This has been a frustrating process for me to figure out this restriction. – Tom Nov 11 '20 at 01:30
0

I have implemented simliar functions, here is idea how to do it:

Step 1: perform right click to popup the menu

menuDiv = browser.find_element_by_xpath("//<selector>']")
actionChains.move_to_element(menuDiv).perform()
actionChains.context_click().perform()
time.sleep(3)   //better wait for a little while

Step 2: locate the menu item to click and perform click on it

targetMenuItem = browser.find_element_by_xpath("//<selector>")
actionChains.click(targetMenuItem)
actionChains.perform()
LIU YUE
  • 1,593
  • 11
  • 19