0

I am new to python so this is maybe dumb question. I want to pass text into the text field on a website.

test = "testing"
driver = webdriver.Chrome()
driver.get("https://www....")
driver.execute_script('document.getElementById("txt1").value = "test"')

If i do it like this the "test" text is passed. I want to pass value of test variable. What do i need to change? Thank you in advance.

1 Answers1

0

You are passing a string as argument to execute script function. Hence you can just do string interpolation. You can try the following Code

test = "testing"
driver = webdriver.Chrome()
driver.get("https://www....")
driver.execute_script('document.getElementById("txt1").value = "{}"'.format(test))