Rayrun
← Back to Discord Forum

trying to open playwright new tab

trying to open playwright new tab in python but it opens new window Also, when I add user_data_dir, I can't operate on the first screen that opens. I can't switch between tabs and I said it opens as a new window and it's annoying. page2 = context.new_page()

This thread is trying to answer question "How to open a new tab in Playwright using Python instead of a new window?"

4 replies

Could you try something like this:

driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't')

Below is how i swap tabs after I click a button and i return the second tab as the main page for the

# We want to return the new tab that was opened as the new page
        return SignupPage(self.page.context.pages[1])
@notlan585: driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't') Is this code not for selenium ?

driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't') Is this code not for selenium ?

Oh crap yes, sorry. Does something like this work?

browser = p.chromium.launch()
    page = browser.new_page()

    # Open a new tab
    new_tab = page.context.new_page()
@notlan585: thx ❤️

thx ❤️

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.