0

I am using the below code to highlight the input box in a web page:

JavascriptExecutor js=(JavascriptExecutor)driver; WebElement username= driver.findElement(By.id("email")); js.executeScript("arguments[0].setAttribute('style','border: solid 2px red');", username); 

It is giving me an error like this:

org.openqa.selenium.WebdriverException: unknown error: arguments[0].setAttribute is not a function 

Note: The tag in the web page already has a style attribute in it.

1
  • Any reason to use JavascriptExecutor and not Java functions? Commented Jan 24, 2018 at 6:46

2 Answers 2

1

I think your syntax is wrong, you forget to add ''quotes near style and also remove ; before username

try this code:

JavascriptExecutor js=(JavascriptExecutor)driver; WebElement username= driver.findElement(By.id("email")); js.executeScript("arguments[0].setAttribute('style','border: solid 2px red')", username) 
Sign up to request clarification or add additional context in comments.

1 Comment

No your answer did not help...typo was here in SO not in my code
0

You are missing quotes, please try the following code,

JavascriptExecutor js=(JavascriptExecutor)driver; WebElement username= driver.findElement(By.id("email")); js.executeScript("arguments[0].setAttribute('style','border: solid 2px red');", username); 

2 Comments

After adding the missing quote also getting the same error. @Murthi
alternatively, you can try arguments[0].style.border='solid 2px red';

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.