Is it possible to get element value using jQuery? I have a web page and I need to get inner text of a div.
You can use ‘Execute Javascript’ keyword to achieve this as long as jQuery is just a kind of Javascript execution.
Thanks. However, I still have problems. The following code returns ‘0’, even though it should return other values, depending on the targeted element. Note that $(“xyz”)[0].textContent selector returns correct values when used in chrome dev tools console.
variableName = WebUI.executeJavaScript(‘return $(“xyz”)[0].textContent’, [])
println(variableName)
Any ideas?
I also tried the following:
Integer variableName = WebUI.executeJavaScript(‘return $(“xyz”)[0].nodeValue’, []) //returns null
Integer variableName = WebUI.executeJavaScript(‘return $(“xyz”)[0].textContent’, []) //returns 48
According to the current state, the correct value returned should be 1.
$(“xyz”)[0].textContent returned values in ASCII code. I used
int variableName = Integer.parseInt(WebUI.executeJavaScript(‘return $(“xyz”)[0].textContent’, [])) to get the correct value.