1
下部分是方法:如何處理TypeError:__call __()至少需要2個參數(給出1個)?
from enum import Enum
from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
class KeyMouseOperation(Enum):
CONTEXT_CLICK = 1
DOUBLE_CLICK = 2
DRAG_AND_DROP = 3
CLICK_AND_HOLD = 4
def keymouse(url, operation_by , elementxpath):
driver = webdriver.Chrome()
driver.get(url)
time.sleep(1)
driver.maximize_window()
time.sleep(1)
if operation_by == KeyMouseOperation.CONTEXT_CLICK:
result = ActionChains(driver).context_click(driver.find_element_by_xpath(elementxpath)).perform()
if operation_by == KeyMouseOperation.DOUBLE_CLICK:
result = ActionChains(driver).double_click(driver.find_element_by_xpath(elementxpath)).perform()
if operation_by == KeyMouseOperation.DRAG_AND_DROP:
result = ActionChains(driver).drag_and_drop(driver.find_element_by_xpath(elementxpath), driver.find_element_by_xpath(elementxpath)).perform()
if operation_by == KeyMouseOperation.CLICK_AND_HOLD:
result = ActionChains(driver).click_and_hold(driver.find_element_by_xpath(elementxpath)).perform()
else:
time.sleep(3)
這是該方法的實例:
from method.key_Mouse import *
KM = KeyMouseOperation()
KM.keymouse("https://www.baidu.com", KeyMouseOperation.CONTEXT_CLICK, "//*[@id='kw']")
,但結果卻是:
C:\Python27\python.exe C:/Users/chenjia/PycharmProjects/AutomationTestSuite/Case/practice.py
Traceback (most recent call last):
File "C:/Users/chenjia/PycharmProjects/AutomationTestSuite/Case/practice.py", line 46, in <module>
KM = KeyMouseOperation()
TypeError: __call__() takes at least 2 arguments (1 given)
Process finished with exit code 1
如何應對TypeError: __call__() takes at least 2 arguments (1 given)
?