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.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With