1

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?

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

This was the issue. It was odd considering the arguments to the function were strings from a list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.