I am trying to add an event to a button:
str = "a#fCoverage" // my locator
def str2 = "\$('" + str + "').addEventListener('click', function(){alert('text')});" // add event
js.exec(str2)
But I get this error:
error: org.openqa.selenium.WebDriverException: unknown error: $ is not defined
Could anyone help me please?
Use document.querySelector
inplace of $
Your code would end up
str = "a#fCoverage" // my locator
def str2 = "document.querySelector('" + str + "').addEventListener('click', function(){alert('text')});" // add event
js.exec(str2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With