Hi, we have tried both options, the first one doesn't seem to find the
popup window when it is invoked by the browser directly, testing xss
vulnerability, instead of when invoking it in markup. For example, I
am trying this:

1)
  returned = @browser.alert do
    @browser.goto('http://
www.url.com/"+void(document.cookie="authorization=true")+alert(document.cookie)+"')
   end

   returned.should == "ok"
# Doing positive test first

but it doesn't find the alert box when it is displayed, and it is not
working when I am setting the URL outside the block as well.

2)
Option two, however, does work, but only for firefox, and I would want
it to work for all browsers with watir-webdriver.

unless (@browser.driver.switch_to.alert.text.nil?)
 #raise "Javascript popup box is found, malicious code might be able
to insert on page"
end

Option one works when it is invoked from a button, but not when
javascript is invoked from browser url. Can someone please help me?

Best Regards
Matt


On Mar 3, 3:52 pm, Jari Bakken <jari.bak...@gmail.com> wrote:
> On Thu, Mar 3, 2011 at 2:12 PM, Usman Hussain <usmanhhuss...@gmail.com> wrote:
> > Hi Guys,
>
> > Im doing a test at the moment where when I enter in something into the
> > url it brings up a Javascript pop up.
> > Now  I do not want to turn the pop up function off by writing some
> > Javascript and then using @b.execute_script etc...
>
> > What I would LIKE to do is to somehow interact with the javascript pop
> > up and click on the button to close it.
> > Is there any way i can do it using the Watir or Webdriver Api or
> > something?
>
> > The pop up is an ALERT box.
> > I am using a MAC
> > I am using Watir-Webdriver with Cucumber
> > Ruby v1.8.7
>
> > any more info please shout.
> > Any help would be awesome.
>
> There are two ways to do this:
>
> 1. Use watir-webdriver's execute_script hacks:
>
>   require 'watir-webdriver/extensions/alert'
>
>   browser.alert do
>     # perform action that triggers alert
>   end
>
> Seehttps://github.com/jarib/watir-webdriver/blob/master/spec/alert_spec.rb
> for more examples.
>
> 2. Use WebDriver's alert handling API directly (currently Firefox-only
> and considered experimental)
>
>   # perform action that triggers alert
>   browser.driver.switch_to.alert.accept
>
> More examples of this 
> herehttp://code.google.com/p/selenium/source/browse/trunk/rb/spec/integra...
>
> Jari

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to