打开右键菜单,然后使用Selenium + Python从菜单中选择一项

时间:2014-09-18 19:44:37

标签: python selenium

我尝试从网页打开右键菜单然后选择其中一个选项(例如打印...)?我使用selenium和python。有谁知道怎么做?非常感谢!

1 个答案:

答案 0 :(得分:0)

我不知道我是否理解你。

例如试试这个:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://www.google.pl")
driver.find_element_by_xpath(".//*[@id='gbwa']/div[1]/a").click()
driver.find_element_by_xpath(".//*[@id='gb36']/span[1]").click()
element = driver.find_element_by_xpath("//body")
element.send_keys(Keys.CONTROL, 'p')
print driver.current_url
driver.close()

And read about xpath

相关问题