Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change focus to parent element using NightwatchJS #80

Closed
diegomejia opened this issue Mar 13, 2014 · 12 comments
Closed

Change focus to parent element using NightwatchJS #80

diegomejia opened this issue Mar 13, 2014 · 12 comments

Comments

@diegomejia
Copy link

It is possible to move deeper into the DOM tree using the .frame JSON Wire Protocol call but I haven't been able to figure out a way to move upward through the DOM tree.

module.exports = {
    "Enter and exit iframes in tree" : function(browser){
        browser
            //Currently focus is at top level.
            .frame('iframeOne')
            //Focus is now enters inner frame iframeTwo
            .frame('iframeTwo')

            //Attempt to move to frame directly
            .frame('iframeOne')
            //Selenium Error 'no such frame'

            //Attempt to move focus up to iframeOne by searching from root.
            .element('id', 'iframeOne', function(e){
                browser.frame(e.value);
            }
            //Selenium Error 'no such element'

}

There is a JSON Wire Protocol call frame/parent that is able to move up to the parent element but it is not currently supported by NightWatchJS. Any suggestions would be appreciated.

@diegomejia
Copy link
Author

I was able to get around this problem by resetting the focus back up to the top level element and crawling down again.

    .frame(null)
    .frame('iframeOne')

It's a workable solution.

@beatfactor
Copy link
Member

Cool, I'll make sure to add the frame/parrent in the next version.

@diegomejia
Copy link
Author

I asked the same question on StackOverflow and I got a response that brought up the point that this is a frame/parent is a brand new JsonWireProtocol spec. The suggestion was to use driver.switchTo().defaultContent() instead. The full post can be found in the link below.

I just thought it would be worth mentioning.

http://stackoverflow.com/questions/22392992/change-focus-to-parent-element-using-nightwatchjs/22412249#22412249

@beatfactor
Copy link
Member

I think that may be the same as .frame(null)

@beatfactor
Copy link
Member

Added in 0.4.8

@vsergi23
Copy link

vsergi23 commented Dec 2, 2014

helpful
thanks @beatfactor

@possibilities
Copy link

Seems like moving up and down frames is impossible using SafariDriver. Is this true or am I missing something?

@Crusader4Christ
Copy link

frame/parrent do nothing, .frame(null) and defaultContent() refreshes the page to start url (it changes while test with redirect). How I can just switch to the parent frame without changing url or refreshing the page?
Now only one workaround I found - just refresh page directly, to get out of iframe

@senocular
Copy link
Contributor

senocular commented Jul 22, 2016

@Crusader4Christ I am working with a web app using iframes and have had no problem jumping to and from the top frame using frame(null). Doing so does not refresh the page, rather, simply changes focus to that frame so element commands are able to target elements within that frame.

P.S. Using the safari driver at that

@Crusader4Christ
Copy link

Crusader4Christ commented Jul 26, 2016

@senocular
here is the code

.waitForElementVisible('//*[@id="iframeModal"]/div/div/div[1]/h4', 25000, false)
        .pause(3000)
        .frame('iframe_payment', function () {
            browser
                .useCss()
                .waitForElementVisible('#pop_up_window input[type=password]', 25000, false)
                .setValue('#pop_up_window input[type=password]', 'hint')
                .waitForElementVisible('#pop_up_window .p_right input.CustomButton[type=submit]', 25000, false)
                .click('#pop_up_window .p_right input.CustomButton[type=submit]')
                .pause(4000)
        })
        .pause(1000)
        .refresh()
        .useXpath()
        .waitForElementVisible('//*[@id="accounts-deposit-table"]/thead/tr/th[1]', 25000, false)

I try to use frame(null) inplace of refresh() but no luck - nightwatch can`t get access to '//*[@id="accounts-deposit-table"]/thead/tr/th[1]' after that and jumps on previous page. I try frame(null) inside function too. Somebody knows what is the problem?

@senocular
Copy link
Contributor

@Crusader4Christ does your clicking submit do anything that might mess with the state of the page? Have you tried pulling out some of the commands like that to see if that helps - basically just have the frame calls and maybe a waitFor or two just so you know that the change of frame context was made. Then maybe you can see if some other command is messing with the frames.

Also, FWIW, you don't have to use the frame callback to perform actions in that frame. You can chain it right off of the frame call:

        .pause(3000)
        .frame('iframe_payment')
        .useCss()
        .waitForElementVisible('#pop_up_window input[type=password]', ...

@senocular
Copy link
Contributor

... though, concerning the frame callback, have you checked the result argument for any error data in the failure case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants