Bryan Wheeler
Bryan Wheeler

Reputation: 125

Selenium issue in using a function argument for send_keys value

My issue involves using Selenium to take the values of a list and passing them to a WebElement with send_keys.

assuming list_item_1 and list_item_2 were imported via spreadsheet and arg_1 and arg_2 are a specific item of each list:

def run(arg_1, arg_2):
  driver.get(URL_TO_SITE)
  form_element_1 = driver.find_element_by_id('ELEMENT_ID')
  form_element_2 = driver.find_element_by_id('ELEMENT_ID')

  form_element_1.send_keys(arg_1)
  form_element_2.send_keys(arg_2)
  ...
  action.perform()

Running this gives the error:

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py",

line 326, in send_keys for i in range(len(val)):

TypeError: object of type 'WebElement' has no len()

This seems to be a problem isolated to using function arguments as the send_keys argument. Is there a workaround here?

Upvotes: 1

Views: 314

Answers (1)

alecxe
alecxe

Reputation: 473873

It looks like arg_1 and arg_2 are WebElement instances and you probably mean to send their text in send_keys():

form_element_1.send_keys(arg_1.text)
form_element_2.send_keys(arg_2.text)

Upvotes: 1

Related Questions