Certified Selenium Professiona Learning Resources JavaScript Usage

Learning Resources
 

JavaScript Usage


Selenium RC launches the browser with itself as the proxy server (hence you may get certificate warning in some modes) and then it injects javascript - to play the test. This also means it can easily work in ALL browsers/platform - and it can be easily used to test AJAX(unlike professional tools).

Since Selenium is based on JavaScript, you can use it in your tests.It is an excellent way to extract information from the pages for later reuse.

There are 2 methods available:

  • getEval(script): it takes the script as a string, executes it and return the value to which the script evaluates too. In ruby use get_eval or js_eval

    • Using this method, the window object refers to the Selenium context, which is different from the tested application’s JavaScript context

      To work around this, you need to get the application’s window object using currentwindow = this.browserbot.getCurrentWindow() * If you want to get an element, just use element = this.browserbot.findElement("locator")

  • runScript(script): it actually adds a