SamZi SamZi - 3 months ago 16
Javascript Question

I want to make a Javascript browser scripts in console. What syntax is there to click/enter text/find values?

Im a beginner in JavaScript and I want to make scripts in the console of the browser to do tasks. I cant find the syntax to do this. The only command I know of is document.getElementById() however Im struggling to find commands to click or enter text into a search box or something to input text in.
Does anyone know how to do this?

Example of what I want to achieve:

Type Hello into the google search bar and press enter.

Answer

You could use ruby with Capybara and Cucumber to do that https://github.com/jnicklas/capybara and if you still want to use javascript you can inspect the input and get the id and then do this:

document.getElementById('lst-ib').value = "Hello";

and for the click you could try this:

document.getElementsByName('btnK')[0].click();

but it didn't work for me.

And if you want to learn javascript you can do it in codeschool or codecademy for example.