On Thu, Sep 29, 2011 at 10:05 PM, Sat nosur <skoppu123 / yahoo.com> wrote:
> Hi All,
>
> I am relatively new to ruby programming, I am trying to capture if any
> kind of exception happens in a Click method. so, I am using raise and
> rescue in the "Click" method. Looks like I am doing something not
> correctly and the script throws this error "syntax error, unexpected
> kRESCUE rescue =A0Exception =3D> e at line # 152
>
> =A0 =A0 =A0 =A0 =A0 =A0What I am trying to do here is I am checking Id of=
 an object
> , if the id doesn't exist throw an exception, rescue an exception and
> display an exception and continue executing the script
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Could please take a look at the script ( C=
lick method)
> and help me to resolve this issue?. Advance thanks for your help
>
> Yours,
> Sat
>
> Attachments:
> http://www.ruby-forum.com/attachment/6640/isell_regression_script_raise_s=
yntax_error.rb

If you indent your code, you will see it more clearly:

def Click(ie,id,verifyval)
  begin
    writeln 'CLICK- ' + id
    if id.exists?
      $ie.button(:id, id).click

      if id =3D=3D 'TriggerFeedAnchor'
        sleep 10
      elsif id =3D=3D 'onestop'
        sleep 20
      else
        sleep 8
      end
    else
      raise Exception  "ID RETURNED #{id}."
  rescue  Exception =3D> e
    puts e.message
  #  puts $!
    break
  end
end
    if $ie.contains_text(verifyval)
      puts "Test Passed. Found the string: on the page #{verifyval}. "
    else
      puts "Test Failed! Could not find the string on the page: #{verifyval=
} "
          end

  end

After the raise, you have to close the if with an end. Rescue comes at
the same scope (same indentation level) as begin. With that fixed, now
you have an extra "end" after "break. You need to remove that:

def Click(ie,id,verifyval)
  begin
    writeln 'CLICK- ' + id
    if id.exists?
      $ie.button(:id, id).click

      if id =3D=3D 'TriggerFeedAnchor'
        sleep 10
      elsif id =3D=3D 'onestop'
        sleep 20
      else
        sleep 8
      end
    else
      raise Exception  "ID RETURNED #{id}."
    end
  rescue  Exception =3D> e
    puts e.message
  #  puts $!
    break
  end
  if $ie.contains_text(verifyval)
    puts "Test Passed. Found the string: on the page #{verifyval}. "
  else
    puts "Test Failed! Could not find the string on the page: #{verifyval} =
"
  end
end

Hope this helps,

Jesus.