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

Not able to find element present in iframe using Serenity JS #233

Closed
AbhineetSharmax opened this issue Jun 7, 2018 · 5 comments
Closed
Labels
enhancement A good idea that should be implemented @serenity-js/protractor Adapter and interactions for Angular Protractor

Comments

@AbhineetSharmax
Copy link

AbhineetSharmax commented Jun 7, 2018

How can i find element present in iframe.. using chrome browser. Thats somewhere down in tree.. @jan-molak

<Iframe id='broker'> <> <> <>

Please, help me find 'raise an issue' which is present in iframe.

@marktigno
Copy link

marktigno commented Jul 19, 2018

Hello! You need to change focus of your test to the iframe element and then find the target object there. Try to use this wrap-up code and use it on your tests:

import { protractor } from 'protractor';
import { Interaction } from 'serenity-js/protractor';
export const Window = {
    switchToFrame: (index: number) => Interaction.where(`#actor switches to a frame`, actor => {`
        return protractor.browser.driver.switchTo().frame(index);
    }),
};

@jan-molak jan-molak added enhancement A good idea that should be implemented @serenity-js/protractor Adapter and interactions for Angular Protractor labels Jul 19, 2018
@marktigno
Copy link

marktigno commented Jul 23, 2018

Oh I almost forgot. You need also this code to return to the parent window:

switchToDefaultContent: () => Interaction.where(`#actor switch back to default`, actor => {
    return protractor.browser.driver.switchTo().defaultContent();
}),

@nbarrett
Copy link
Contributor

nbarrett commented Jul 23, 2018

Hey @jan-molak - I see you've added an enhancement label here - are you considering adding transparent iframe switching into serenity-js as was done in the java version, where the iframe was added as an optional field in Target?

@AbhineetSharmax
Copy link
Author

AbhineetSharmax commented Jul 23, 2018

Hello everyone,

I have Figured it using,

browser.driver.switchTo().frame(0);

Hence, it worked like charm.

@jan-molak
Copy link
Member

jan-molak commented Jul 24, 2018

@AbhineetSharmax - glad you managed to solve the issue, thanks for letting us know!
@nbarrett - yeah, I think we need a nice built-in way of doing that.

@jan-molak jan-molak added this to To do in Serenity/JS Board Mar 14, 2020
@jan-molak jan-molak moved this from To do to In progress in Serenity/JS Board Oct 4, 2020
Serenity/JS Board automation moved this from In progress to Done Oct 5, 2020
jan-molak added a commit that referenced this issue Mar 2, 2022
Interaction to `Switch.to(switchable)` works for both `Page` and `PageElement` now. For
`PageElement`, if the element represents a `frame` or `iframe`, `Switch.to(element)` switches the
top-level browsing context to that frame. When a `PageElement` represents any other HTML element,
invoking `Switch.to(element)` sets browser focus on that element.

re #82 #227 #233 #365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A good idea that should be implemented @serenity-js/protractor Adapter and interactions for Angular Protractor
Projects
Development

No branches or pull requests

4 participants