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

[Question] Java Handle New Page #627

Closed
arman-ygh opened this issue Sep 24, 2021 · 11 comments
Closed

[Question] Java Handle New Page #627

arman-ygh opened this issue Sep 24, 2021 · 11 comments

Comments

@arman-ygh
Copy link

Hello,

The website I would like to handle forces interaction with a new tab, which opens after clicking a button. It looks like this: (See attached screenshot)
image

Main aim is to wait for the popup, print the source code and click on "Go" afterwards.

Could you be so kind and attach the Java code snippet for this please? I already had a look at Java docs, but could not integrate it.

Thank you very much.

@mxschmitt mxschmitt transferred this issue from microsoft/playwright Sep 24, 2021
@yury-s
Copy link
Member

yury-s commented Sep 24, 2021

See this guide. You need to wrap the click into Page.waitForPopup, something along these lines:

Page popup = page.waitForPopup(() -> {
  page.click("<your button selector>");
});

@yury-s yury-s closed this as completed Sep 24, 2021
@arman-ygh
Copy link
Author

arman-ygh commented Sep 24, 2021

So I am using this snippet:

Page popup = page.waitForPopup(() -> {
				page.click("//*[@id=\"__next\"]/div[1]/main/div/div/div/div[1]/div[2]/button");
			});

System.out.println("Content: " + popup.content());

However I am getting a timeout exception, as it cannot find the popup / print the content. Any idea?

@yury-s
Copy link
Member

yury-s commented Sep 24, 2021

Does the popup show up?

@arman-ygh
Copy link
Author

Yes it does. Maybe it's more likely a tab? As you can see at the screenshot above.

@yury-s
Copy link
Member

yury-s commented Sep 24, 2021

Yes it does. Maybe it's more likely a tab? As you can see at the screenshot above.

If it's a window opened by the page as a result of the click it must be intercepted. If it's not there it means that it was either opened before the call or it is not opened by the page (Could it be that you have an extension that opens the child window?). You can also listen for all pages created in the context via contenxt.onPage to see if it's created as a normal page. Which browser is this?

@arman-ygh
Copy link
Author

Yes, you are right. It is an extension, which opens the windows after clicking a button. I am using Firefox. What would be the best solution in my case?

@yury-s
Copy link
Member

yury-s commented Sep 24, 2021

We don't support extensions in Firefox yet, you can +1 this bug if you are interested in it.

@arman-ygh
Copy link
Author

Thank you. How can I use playwright with extensions - will chromium work? If yes, can you show me the corresponding doc page?

@yury-s
Copy link
Member

yury-s commented Sep 24, 2021

@arman-ygh
Copy link
Author

Is there also a description in Java? If not, could you please be so kind and send me a code snippet, which would solve my issue?

Really appreciated. Also, thanks for the fast answers.

@yury-s
Copy link
Member

yury-s commented Sep 24, 2021

Sorry, I forgot to mention that the background pages API is not exposed in Java, there is a feature request for that, so far we've been resisting it as it is a not a standard web api.

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

No branches or pull requests

2 participants