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.

0

1 Answer 1

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))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.