My Blog List

Sunday, November 13, 2011

Selenium Rare Tips - Part II

1. Get Browser Name, Version and Environment Details
Java Script Expressions which you can use by Selenium.getEval to get the values.


  1. navigator.appCodeName   //For Browser Name
  2. navigator.appVersion    //For Browser Version
  3. navigator.userAgent     //For both details
  4. navigator.appName       //For Browser Name
  5. navigator.cookieEnabled //Cookie enabled or not
  6. navigator.platform      //OS


2. Get Current URL
selenium.getLocation()

3. Scroll Bar Position

  1. Actual Width/Height of element:(Excluding ScrollBar)
  2. selenium.browserbot.getCurrentWindow().document.getElementByid('css#id').clientWidth
  3. selenium.browserbot.getCurrentWindow().document.getElementByid('css#id').clientHeight
  4. Max Scroll Position:
  5. scrollWidth - clientWidth    //Max Horizontal Scroll Position
  6. scrollHeight - clientHeight  //Max Vertical Scroll Position
  7. Current Scroll Position:
  8. scrollLeft
  9. scrollTop

If you are using Selenium 1.0, use this.browserbot
If you are using Selenium 2.0, use selenium.browserbot

4. JavaScript Expression execution in Selenium 2.0

  1. JavascriptExecutor js = (JavascriptExecutor)driver;
  2. String title = (String) js.executeScript("return document.title");
  3. System.out.println(title);
  4. String script = "var ele = document.getElementsByTagName(\"a\");" +
  5.                 "return ele[0].getAttribute(\"title\");";
  6. String titleName = (String) js.executeScript(script);






1 comment:

  1. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete