0

I am trying to use a Javascript snippet to make sure two divs having some text co exist in another one [ Basically validate the existence of a comment on a certain post ]

The JS works on firebug but fails on selenium IDE.

javascript{
  return ($.grep(  $("#Posts li") .map(function(index,element){
    if($(element).has(".puls_content:contains('post text')").length > 0){
      if($(element).has("*:contains('this is a comment')").length > 0) {
        return true
      }
    }
    return false
  }) , function(x){ return x}).length > 0) }

I get the Unexpected Exception error from selenium-api.js, any help ?

meetar
  • 7,443
  • 8
  • 42
  • 73

1 Answers1

0

Selenium doesn't run javascript in the same context as firebug would. You are actually running from the selenium window outside the window you are testing. But never fear! They have thought of this. You will need to add something like

var jQuery=selenium.browserbot.getUserWindow().jQuery;

into your script and change all your $ to jQuery to get it to work the way you want it to. Check out this question and answer.

Secondly, I would suggest doing this with CSS or Xpath selectors and verifying the post and then the comment section separately. It would cause you to go through less hoops to figure out what you need.

Community
  • 1
  • 1
General Redneck
  • 1,240
  • 2
  • 13
  • 28