Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variables through Selenium send.keys instead of strings

I'm trying to use Selenium for some app testing, and I need it to plug a variable in when filling a form instead of a hardcoded string. IE:

this works name_element.send_keys("John Doe")
but this doesnt name_element.send_keys(username)

Does anyone know how I can accomplish this? Pretty big Python noob, but used Google extensively to try and find out.

like image 732
adamjmagyar Avatar asked Sep 05 '12 21:09

adamjmagyar


2 Answers

In at least one case, I found that I couldn't pass a variable to send_keys unless I first passed a regular empty string:

inputElement.send_keys("")
inputElement.send_keys(my_text_variable)

It also works as a list:

inputElement.send_keys("", my_text_variable)

like image 131
meetar Avatar answered Oct 06 '22 09:10

meetar


Try this.

username = r'John Doe'

name_element.send_keys(username)

I was able to pass the string without casting it just fine in my test.

like image 39
Clint Hart Avatar answered Oct 06 '22 10:10

Clint Hart