如何摆脱上下文点击在python硒?



这已经问过之前这里:如何隐藏上下文点击?硒Chromedriver

但是没有一个解决方案对我有效。我的网页上有一个元素,需要右键选择它(很奇怪,但这对网站来说是有意义的)。我可以使用

点击这个元素
action.context_click(src).perform()

我已经试过摆脱右键点击4次后弹出的菜单

# Left-clicking in the same spot after I have right-clicked
action.click().perform()
# Hitting the space bar
webdriver.ActionChains(self.driver).send_keys(Keys.SPACE).perform()
# Hitting the escape key
webdriver.ActionChains(self.driver).send_keys(Keys.ESCAPE).perform()
# Clicking on an unused element
action.move_to_element(WebDriverWait (self.driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "html"))))
action.click().perform()
# Reloading the page did not get rid of it either
self.driver.refresh()

这些方法都不能消除弹出的菜单。我不能重新加载页面来摆脱这个,否则它会取消选择我试图获得的对象。这并不影响我的程序,但它是恼人的有它在我的方式,当我试图观看我的程序正在做什么。任何帮助都是感激的!这是我的业余时间,所以它不是时间敏感的。

我试图打开上下文菜单(右键单击)在一个随机的网站,然后我能够关闭它与pyautogui(pip install pyautogui)

action.context_click(src).perform()
import pyautogui    
pyautogui.press('esc')

有可能你必须按几次esc

最新更新