Nightwatch: Frames Element in Page Objects are not recognized in new version

Created on 12 Feb 2019  Β·  21Comments  Β·  Source: nightwatchjs/nightwatch

After updating to the new version, a test using iframes is failing with the error:
Error while running .switchToFrame() protocol action: no such frame
The test is using a page object with this example function:

fillExpDate: function(browse, expDate) {
const self = this;
this.api.elements('css selector', 'iframe[title='input frame']', function(frames) {
self.api
.frame(null)
.frame(frames.value[1])
.click('input[name=exp-date]')
.setValue('input[name=exp-date]', expDate);
return this;
},

The test did not fail before the update.

bug

Most helpful comment

@ptalje thanks, this is useful.

All 21 comments

Ok, but please have a look at the contributing guidelines for submitting an issue and try to include the information as detailed there.

I got the same issue, pls help to fix it , thanks

I have the same problem, when trying to switch to the first frame using frame(0) this error appears
Error while running .switchToFrame() protocol action: no such frame
but when i try to switch to the 2nd frame using frame(1) it works as expected.
I tried with chromedriver & geckodriver
Here is my configuration

windows : 10, nightwatch:1.0.19, chromedriver: 2.46.0, geckodriver : 1.14.1

So have you ruled out the possibility that there might not be a frame 0?

On Wed, 13 Feb 2019 at 15:07, mdz15 notifications@github.com wrote:

I have the same problΓ©me, when using trying to switch to the first frame
using frame(0) this error apear
Error while running .switchToFrame() protocol action: no such frame
but it works when i try to switch to the 2nd frame using frame(1)
I tried with chromedriver & geckodriver
Here is my configuration

'"geckodriver": "^1.14.1",
"nightwatch": "^1.0.19",
"chromedriver": "^2.46.0"'

β€”
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/nightwatchjs/nightwatch/issues/2026#issuecomment-463211640,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAZmst7mtUhE-hqdn_zJKNq5-p6-MBWCks5vNBw2gaJpZM4a3ObC
.

@beatfactor Actually, there is a frame 0, the script I'm using was working perfectly under Nightwatch 0.9.21 but after trying to use the current version (1.0.19) , I could not change the focus to the first frame ( frame 0 )

@beatfactor Actually, there is a frame 0, the script I'm using was working perfectly under Nightwatch 0.9.21 but after trying to use the current version (1.0.19) , I could not change the focus to the first frame ( frame 0 )

Here is an example ( the link is inside ) :

module.exports = {
  'Demo Frames' : function (client) {
    client
    .url("https://antaki.me/frames/index.html").useXpath()
    .waitForElementVisible("//frame[@name='Header']",60000).pause(1000)
    .frame(0).waitForElementVisible('//select[@id="cmbUserGroups"]',10000)
    .click('//select[@id="cmbUserGroups"]/option[contains(text(),"Espace Collaborateur")]')
    .frame(null).pause(1000)
    .frame(1).pause(1000)
    .click('//a[@id="open-google"]')
    .end()
  }

Upadate :
Actually targeting frame by an integer ( position ) is not working, however targeting frame using identifiers ( name ) is working

@mdz15 so we can close this issue then?

@beatfactor is there a way to change to focus to frames that doen't have a name nor an id ?, because I was using indexes with nightwatch 0.9.x and it was working fine, but in 1.0.19 it seems that it is not working

@mdz15 if both versions are using the same Selenium/Webdriver versions, drivers there is no reason why it shouldn't work in Nightwatch v1. So if you are in a position to explain what the difference in behaviour is Nightwatch v1 please do so and we'll fix it (you are of course encouraged to submit a PR).

@beatfactor I'm working on a custom command for NightwatchJS and the thing that I need to happen is to iterate over all the iFrames in a page and select them with their Selenium ID. The only way I've been able to actually switch focus to any frames is with the id= attribute. The expected behavior is that I can use the Selenium ID to switch focus/context to the iFrame.

I am getting the same error after upgrading to 1.0.21 while the same test case works flawless on 0.9.21, using the same Chromedriver 2.46.628402 on both setups.
On Windows 7, I use NodeJS 10.14.1 while on our test server running Ubuntu 18.04 LTS we have NodeJS 8.10.0

The test case I have, where I have made an effort to be as thorough as possible during debugging, although you can get the same result with less steps.

  'iframe test': function(browser) {
    browser
      .useXpath()
      .url('https://www.quirksmode.org/iframetest.html')
      .waitForElementPresent('//body', 'Loading page')
      .waitForElementPresent('//iframe', 'Loading iframe')
      .elements('xpath', '//iframe', function(result) {
         result.value.forEach((frame) => {
           browser.elementIdAttribute(frame.ELEMENT, 'src', (attr) => {
             if (attr.value) {
               console.log('Found an iframe with src ' + attr.value);
               browser.frame({ELEMENT: frame.ELEMENT}, () => {
                  console.log('I should be navigating within iframe');
                  browser
                    .waitForElementPresent('//h1','Iframe text')
                    .getText('//h1',function(result) {
                      console.log('H1 value: ' + result.value);
                    })
                    .frameParent();
               });
             }
           });
         });
      })
    ;
  },

Nightwatch 0.9.21 test run:
√ Loading page
√ Loading iframe
Found an iframe with src https://www.quirksmode.org/iframetest2.html
I should be navigating within iframe
√ Iframe text
H1 value: Test page in iframe

OK. 3 assertions passed. (4.654s)

Nightwatch 1.0.19 test run:
√ Loading page
√ Loading iframe
Found an iframe with src https://www.quirksmode.org/iframetest2.html
Error while running .switchToFrame() protocol action: no such frame

I should be navigating within iframe
√ Iframe text
H1 value: Iframe test
OK. 3 assertions passed. (405ms)

@ptalje could you please post the verbose log output when running in each version?

Yeah, I found the same error. Here is a PR that should fix it https://github.com/nightwatchjs/nightwatch/pull/2040

Here is the verbose output, the term qwerty is from a script in package.json that performs: nightwatch -t test/iframe.js. And by the way @hcmec great job submitting a PR, hopefully this will solve the problem for iframes without name/id!


Verbose output 0.9.21
C:\Development\gamlanatten>npm run qwerty --verbose

Does anyone know of a fix for this yet?
There is no information in my verbose relating to the issue.
I am getting the same issue however it runs fine in nightwatch-cucumber.
If I use the same chromedriver and selenium driver within the nightwatch-api framework the issue still persists.
It would be great to find a resolution to this -

image

"devDependencies": { "cucumber": "^5.1.0", "nightwatch": "^1.0.19", "nightwatch-api": "latest", "selenium-server-standalone-jar": "^3.141.5" }

Step_def:
` return client
.pause(2000)
// return client.verify.containsText('#Step3Panel .HPPContainer h2', 'Order total')
.verify.containsText('#Step3Panel .HPPContainer li span', 'Total to pay:')
.element('css selector', 'iframe[src*="/HPP.aspx"]', (frame) => {
client.frame({ELEMENT: frame.value.ELEMENT}, () => {

                return pageObj
                    .click('#pas_ccnum')
                    .setValue('#pas_ccnum', '4123456789')
                    .setValue('#pas_expiry', '1219')
                    .setValue('#pas_cccvc', '121')
                    .setValue('#pas_ccname', '1J Doe')
                    .click('#rxp-primary-btn') 
            });
    });
});`

As stated above the PR that should fixed it #2040
Thanks πŸ‘

Sorry for the delay here.

@ptalje verbose log output wasn't very useful as it's the NPM log output, not the Nightwatch output.

The referenced PR #2040 also doesn't provide any details and the only meaningful change there is from String(frameId) to just frameId alone.

We cannot merge this PR if we don't have a clear understanding of the situation. So if anyone who is invested in this fix would kindly provide a relevant verbose log of the commands that are issued and also your version details, that would help a lot with moving this forward.

Otherwise it will just have to wait until we find a time to properly reproduce the issue, write some unit tests etc. And that is a bit unfortunate in my opinion, for such a trivial issue.

And if anyone does provide a verbose log, please format it properly.

Sorry about that, hopefully this makes more sense. Unfortunately I haven't got Nightwatch 0.9.x to work on this computer yet so here's only for 1.0.19

1.0.19:

PS C:\Development\nightwatch> .\node_modules\.bin\nightwatch --verbose -t test/iframe.js
 Starting ChromeDriver on port 9515...
 ChromeDriver up and running on port 9515 with pid: 5188 (147ms).

[Iframe] Test Suite
===================
  β†’ Running command: elements ('xpath', '//iframe', [Function])
   Request POST  /session/747475514a6555c64283232f7d3e255d/elements
   { using: 'xpath', value: '//iframe' }
   Response 200 POST /session/747475514a6555c64283232f7d3e255d/elements (11ms)
   { sessionId: '747475514a6555c64283232f7d3e255d',
     status: 0,
     value: [ { ELEMENT: '0.32240952516330057-2' } ] }
 β†’ Completed command elements ('xpath', '//iframe', [Function]) (14ms)

 β†’ Running command: frame ({ELEMENT, [Function])
   Request POST  /session/747475514a6555c64283232f7d3e255d/frame
   { id: '[object Object]' }
   Response 200 POST /session/747475514a6555c64283232f7d3e255d/frame (8ms)
   { sessionId: '747475514a6555c64283232f7d3e255d',
     status: 8,
     value:
      { message: 'no such frame',
        error:
         [ '  (Session info: headless chrome=72.0.3626.121)',
           '  (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17134 x86_64)' ] } }
 Error while running .switchToFrame() protocol action: no such frame

I should be navigating within iframe
 β†’ Completed command frame ({ELEMENT, [Function]) (12ms)
 ChromeDriver process closed.

@ptalje thanks, this is useful.

I'm receiving the same error when simply have frame(null) in page-object method or even in test

Error:
Error while running .switchToFrame() protocol action: no such frame

Issue appeared after updating to 1.0.19 version from 0.9

Enough to add browser.frame(null); to test and issue will be reproduced

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davecranwell picture davecranwell  Β·  3Comments

lgaticaq picture lgaticaq  Β·  3Comments

sgleonardoopitz picture sgleonardoopitz  Β·  3Comments

bushev picture bushev  Β·  4Comments

davidlinse picture davidlinse  Β·  4Comments