Reputation: 47
I want to pass python variable in to javascript. The variable value is an element id and so I want to pass this variable having element id to javascript "getElementById"
I tried -
element = 'id_of_element'
js = """
var element = document.getElementById(""" + element + """)
"""
But I get error - WebDriverException: Message: u'element is null'. Please advise. I am newbee to this.
Upvotes: 0
Views: 1536
Reputation: 107287
you can use format
:
element = 'id_of_element'
js = """
var element = document.getElementById("{}")
""".format(element)
Upvotes: 0
Reputation: 47
I found the solution -
You have to use a single quote around around the three double quotes
Like this -
element = 'id_of_element'
js = """
var element = document.getElementById('"""+element+"""')
"""
Upvotes: 1