1

I'm trying to set a basic variable "a" to use with javascript executor in selenium, but gives a variable not defined error.

I dont know javascript, so not sure how to define a variable for javascript executor.

Thanks.,

a = 12

driver.execute_script('document.getElementById("FormRow-BUY-price").value=a;')

1 Answer 1

1

You aren't passing this value to JS

driver.execute_script('document.getElementById("FormRow-BUY-price").value='+str(a)+';')

This is one of many solutions, other might be string formatting or if you want this value to be accessible in js, you can do

driver.execute_script('a='+str(a)+';')

after any change of a variable

Sign up to request clarification or add additional context in comments.

1 Comment

@GenusMax : If this worked for you, Mark this as a accepted answer.

Your Answer

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