如何点击selenium python中的右键菜单?

时间:2017-10-27 20:49:46

标签: python python-3.x selenium automation

我试图点击右键菜单,我可以打开右键菜单,但它没有点击任何菜单或没有按任何键,如向下,向上等我错了:

profile_pic=driver.find_element_by_css_selector('img[class="profilePic img"]')
okl=profile_pic.click()
time.sleep(5)
action1=ActionChains(driver)
action1.context_click(okl).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()

1 个答案:

答案 0 :(得分:0)

这是一个可行的版本:

  

首先右键单击以显示菜单

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
targetMenu = browser.find_element_by_xpath("//<selector>")
actionChains.click(targetMenu)
actionChains.perform()