Currently, I am utilizing C# and Selenium to browse through a website and have come across an issue regarding passing variables into my JavaScriptExecutor command. When I attempt to do so using the code below:
((IJavaScriptExecutor)webdriver).ExecuteScript("document.getElementByID('text box1').value = 'hello'");
Everything runs smoothly. However, when I try to use variables instead, it gives me an error stating that they are not defined:
var elementID = "text box1"
var fieldValue = "hello"
((IJavaScriptExecutor)webdriver).ExecuteScript("document.getElementByID(elementID).value = fieldValue");