-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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] How to switch between tabs in same context? #1443
Comments
Hi @sarut0bi, pages in Playwright behave as if they are active and visible throughout execution, and do not require manual switching. Can you elaborate more on why you would like to switch between tabs? |
if i have to interract from a backoffice front for example:
|
Thanks. I'm not entirely sure I follow. It would be possible to reload the page 1. How would setActivePage particularly help? Are you running the execution headfully? Is there manual intervention involved (not from JS code)? |
i thought i can't interract on page1 once page2 is opened in fact:
=> it works as it should :) (sorry for mistake) |
what if clicking on a link in page1 opens new tab? How to handle this situation? |
@Bharath-Kumar-S you can handle new tabs by listening to |
If 2 tabs of same context are opened by let context = await browser.newContext(); How to move focus back to page1? |
You can use page1 variable to access google.com tab and page2 to access ebay.com tab. You don't have to switch it like how we do it in selenium or protractor. |
Both page1 and page2 will be active. |
My product is based on the visibility, what an end user is viewing. So despite of having control of elements in all pages I need to switch between the tabs or pages. So if we have some thing to aching it using playwright please share. |
Yes, what is the document.visibilityState of each Page ? |
@sublimator thanks for suggestion but you completely missed it. I am asking the functionality to change the tab or switch to previous tab in playwright. I am not trying to implement any event listener functionality. In simple words ability to change or switch the browser tab using playwright if we can. |
Yes, need too! |
Sorry, I was actually asking what the visibility state of each Page is supposed be if you simply use the Page handles as if they had focus. What if your page does something based on the visibility state? I want to test an extension and in puppeteer we can use page.bringToFront() to focus a given tab. |
|
# Get page after a specific action (e.g. clicking a link)
with context.expect_page() as new_page_info:
page.click('a[target="_blank"]') # Opens a new tab
new_page = new_page_info.value
new_page.wait_for_load_state()
print(new_page.title()) please refer to this link.https://playwright.dev/python/docs/multi-pages?_highlight=multi#handling-new-pages |
@Bharath-Kumar-S Can you please let me know if you are able to handle multiple tabs in playwright and switch between them? |
Assume you only created one page (via browser context), but for some reason, new pages/tabs open. |
Currently i am unable to switch between tabs i explain:
=> Is there a way to do context1.setActivePage(page1) ?
I should also create another context but if each page need his own context what is the gain of context?
The text was updated successfully, but these errors were encountered: