Cannot read a field value from a webpage by KM

I would like to read a field value from a webpage by using JS querySelector. The script worked when I tried in the Chrome JS console but it didn't work when I tried in KM.

For example, I would like to read the search field in the Google frontpage.

I used the following script in the Chrome JS console. It returned the value "Hello".
document.querySelector("#APjFqb").value;

However, I got nothing when I used the same script by KM.


It will be grateful if anyone would help me to solve this problem. Thank you very much!

You can either change your query to this:

return document.querySelector("#APjFqb").value;

Or use the disclosure triangle to the left of the JavaScript command and disable Modern Syntax. You can read more about it in the wiki, but here's the relevant bit:

In version 11.0, scripts default to Modern Syntax, which essentially wraps the script in etc ... This helps keep your script from interacting with the web page in unexpected ways. A result of this is that you need to return values to the action using the return syntax.

-rob.

1 Like

Thank you very much for your prompt and helpful response!

1 Like