0

I need to disable same-origin-policy for my autotests. I'm using webdriver.io + selenium standalone server + chromedriver on Ubuntu 16.04. I need to get title from iframe that has domain that differs from page domain. I have read this topic and used answers in my code, but it seems to not work/ Disable same origin policy in Chrome .

My code: Part of wdio.conf.js

capabilities: [{
        maxInstances: 5,
        browserName: 'chrome',
        chromeOptions : {
            args: ["--disable-web-security", "--user-data-dir:path/to/profile"]
        }
    }],

Part of my code in spec to get title of iframe:

it('step' , function() {
  var iframeValue = browser.element('#iframe_id').value;
  browser.frame(iframeValue);
  browser.waitForExist('title'); //or any element inside head or body
  browser.getTitle(); //returns page title, not iframe
  browser.element('title').getText(); //returns ''
  browser.element('title').getHTML(); //returns '<title>iframe title</title>'     
});

I have restarted selenium server, restarted tests, used browser.debug() to check if iframe is an active element, checked that profile --user-data-dir parameter works. Is it possible that webdriver.io can't get values from iframe or --disable-web-security doesn't work at all?

UPDATE: Structure of iframe:

<iframe src="http://www.example.com" id="iframe_id"></iframe>
    #document
    <html>
    <head>
        <title>iframe title</title>
    </head>
    <body>
        <div>
            <!--content-->
        </div>
    </body>
    </html>
Daria Motorina
  • 37
  • 1
  • 21

1 Answers1

0

I dont understand what you want to do but if you do

browser.getHTML('html').then(function(data) {
// match something from data with regex
}

you can match everything you search with a regex. If you are not scrap a random website and you have access to the document then just add a class. then you can make .getHTML or .getText on the class you created. However if you make .getHTML on 'html' then you will get the complete html of the document this means everything you could see in source code you will get.

t33n
  • 220
  • 2
  • 14