CamIce CamIce - 2 months ago 32
Python Question

How to perform right click using Selenium ChromeDriver?

I have been searching for this a lot, but could not find an answer for Python.

Is it possible to simulate right click, or open up the context menu via selenium/chromedriver?

I have seen options for Java, and some other languages, but never in Python.
What would I have to do to simulate a right click on a link, or a picture?

Answer

It's called context_click in selenium.webdriver.common.action_chains. Note that Selenium can't do anything about browser level context menu, so I assume your link will pop up HTML context menu.

from selenium import webdriver
from selenium.webdriver import ActionChains

driver = webdriver.Chrome()
actionChains = ActionChains(driver)

actionChains.context_click(your_link).perform()
Comments