缺少1个必需的位置参数-Selenium python

时间:2018-07-12 18:10:09

标签: python python-3.x selenium-webdriver automation

在我的bas类中,我有以下实现。

def find_element(self, locatorMode, Locator):
    locator = CONFIG.LocatorMode
    element = None
    if locatorMode == locator['ID']:
        element = self.driver.find_element_by_id(Locator)
    elif locatorMode == locator['NAME']:
        element = self.driver.find_element_by_name(Locator)
    elif locatorMode == locator['XPATH']:
        element = self.driver.find_element_by_xpath(Locator)
    elif locatorMode == locator['CSS_SELECTOR']:
        element = self.driver.find_element_by_css_selector(Locator)
    elif locatorMode == locator['LINK_TEXT']:
        element = self.driver.find_element_by_link_text(Locator)
    else:
        raise Exception("Unsupported locator strategy")
    return element

我从配置类中选择第2行上的LocatorMode。

def fill_out_field(self, locatorMode, Locator, text):
    self.find_element((locatorMode, Locator)).clear()
    self.find_element((locatorMode, Locator)).send_keys(text)

在测试用例中调用fill_out_field方法时,它给了我错误:

def agentLogin(self):
    self.driver.get(CONFIG.SITE_URL)
    self.assertEqual(CONFIG.SITE_LOGIN_URL, self.driver.current_url)
    self.take_snapshot(self.driver)
    credential = CONFIG.TEST_ACCOUNT
    self.fill_out_field("name", "accountId", credential['accountId'])

错误:

File "/Users/hassan/Documents/GitHub/poseidon/tests/base_test.py", line 155, in fill_out_field
    self.find_element((locatorMode, Locator)).clear()
TypeError: find_element() missing 1 required positional argument: 'Locator'

0 个答案:

没有答案