在python中执行send_key的问题

时间:2016-12-15 15:41:35

标签: python bdd python-behave

尝试登录应用程序时出现以下错误错误。所以我想在用户名文本框中输入用户名。这是示例步骤定义文件 -

username = (By.ID, 'user_name')
password = (By.ID, 'user_password')
signin = (By.ID, 'user_login')
@given('user is logged in to the application')
def step_impl(context):
    driver = context.browser
    driver.get(test_url)
    driver.maximize_window()
    driver.find_element(username).send_keys("test")
    driver.find_element(password).send_keys("test")
    driver.find_element(signin).click()

错误消息如下 -

driver.find_element(username).send_keys("testing")
emote\webdriver.py", line 752, in find_element\webdriver
'value': value})['value']
emote\webdriver.py", line 236, in executeenium\webdriver
self.error_handler.check_response(response)
emote\errorhandler.py", line 192, in check_responseriver
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: unknown error: 'using' must be a string
(Session info: chrome=54.0.2840.99)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f93
4aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)

1 个答案:

答案 0 :(得分:0)

正确的代码是:

driver.find_element(*username).send_keys("test")
driver.find_element(*password).send_keys("test")
driver.find_element(*signin).click()