import unittest
from selenium.webdriver import ActionChains
import win32clipboard as w
import win32con
import time
from selenium import webdriver
#模拟鼠标右键点击
设置剪切板内容
def setText(aString):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_UNICODETEXT, aString)
w.CloseClipboard()
class MyTestCase(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Firefox(executable_path=‘D:\python\driver\geckodriver’)
def test_rightClickMouse(self):
url=“http://www.sogou.com”
self.driver.get(url)
#searchBox=self.driver.find_elements_by_id(“query”)
searchBox=self.driver.find_element_by_link_text(‘新闻’)
#searchBox.click()
#执行鼠标右键单击操作
ActionChains(self.driver).context_click(searchBox).perform()
time.sleep(2)
if name == ‘main’:
unittest.main()