Access iFrames using Nightwatch

I use Nightwatch to verify that the correct value has been assigned divin the iframe.

My html;

<div class="o-ads__inner" id="leaderboard-gpt">
  <div id="google_ads_iframe">
    <iframe id="some_id">
      #document
        <html>
          <head></head>
          <body>
            <div id="ad-data" creative-id="53134803289">
              <!-- All of the stuff -->
            </div>
          </body>
        </html>
    </iframe>
  </div>
  <iframe><!-- Another iframe (I don't want) --></iframe>
</div>

This is my night time test;

module.exports = {
  'Leaderboard Visibility' : function (client) {
    client
    .url(some_url)
    .waitForElementVisible('body', 5000)
    .waitForElementPresent('#leaderboard > iframe', 10000)
    .pause(5000)
    .frame(0)
      .pause(5000)
      .waitForElementPresent('div#ad-data', 5000)
      .assert.attributeContains('div#ad-data', 'creative-id', '53134803289')
    .end();
  }
};

The error I get from Nightwatch is that Timed out while waiting for element <div#ad-data> to be present for 5000 milliseconds.I know that it is there, checking before an unsuccessful string.

I put 2 .pause(5000), since similar questions suggest that it might be a problem that the contents in the iframe are not loading fast enough. I don't think the case here is due to some debugging that I did, but I left them there for now.

I think I can’t access div#ad-datait because the iframe has its own property contentDocumentthat contains headboth body(and therefore subsequent divs).

div iframe contentDocument Nightwatch?

+4
2

iframe <iframe id="some_id"> .frame('some_id').

+6

iframe

, , (0) , iframe. .

module.exports = {
      'Checkout Braintree' : function (client) {
        client
        .url('#enter_your_url_here')
        .waitForElementPresent('[data-e2e="brainTree3Ds"]', 10000)
        .pause(5000)
        .perform(() => {
          client.getAttribute('[data-e2e="brainTree3Ds"] iframe', 'id',(result) => {
            client
              .frame(result.value)
              .setValue('input[name="external.field.password"]', 1234)
              .click('input[type="submit"]');
          });
        })
        .testSuccessPage() // External Command
        .end();
    }
+1

Source: https://habr.com/ru/post/1620382/


All Articles