2

Using Watir, I can access the methods of the iframes of the page:

browser.iframes.map(&:contentwindow) 
# => ["", "", ""]

If I am using javascript (inside the same context that I executed the Watir code), I am blocked (for all the iframes):

 script =<<-ENDHEREDOC
 var i = 1;
 var iframes = document.querySelectorAll('iframe');
 all = [];
 for (i = 0; i < iframes.length; i++) {
      all.push(iframes[i].contentWindow);
}  
return all;
ENDHEREDOC

elements = browser.execute_script(script)
Selenium::WebDriver::Error::NoScriptResultError: move target out of 
bounds: Blocked a frame with origin "https://my_site.atlassian.net" from accessing a cross-origin frame.

I suppose that Watir, just like phantomjs, must have something like web-security, option which is set to false by default. And then, it looks like the security is on again for running scripts. Is it possible to keep security off also for the scripts?

ribamar
  • 1,235
  • 14
  • 20

1 Answers1

2

For Chrome, the same origin policy can be disabled using the --disable-web-security argument. To pass this argument from Watir to Chromedriver, you can do:

browser = Watir::Browser.new :chrome, args: %w[--disable-web-security]

Or:

browser = Watir::Browser.new :chrome, options: {args: %w[--disable-web-security]}
Justin Ko
  • 44,820
  • 5
  • 82
  • 95