gpt4 book ai didi

Open multiple tabs in a browser using Playwright(使用PlayWright在浏览器中打开多个选项卡)

转载 作者:bug小助手 更新时间:2023-10-24 20:55:31 24 4
gpt4 key购买 nike



I am trying to open multiple tabs from the same browser using the mentioned playwright code. The browser I'm trying to use is Firefox. Firefox is opening multiple windows instead of tabs. With Chrome it is successfully opening multiple tabs from the same browser. I have searched for different solutions but the result was the same.

我正在尝试使用提到的编剧代码从同一浏览器打开多个标签。我正在尝试使用的浏览器是Firefox。火狐正在打开多个窗口,而不是标签。通过Chrome,它可以成功地从同一浏览器打开多个标签。我寻找了不同的解决方案,但结果是相同的。


import time
from playwright.sync_api import sync_playwright

def run(playwright):
firefox = playwright.firefox
browser = firefox.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("https://google.com")
new_tab = context.new_page()
new_tab.goto("https://playwright.dev")
time.sleep(5)
browser.close()

with sync_playwright() as playwright:
run(playwright)

更多回答

That's not supported yet. There is an issue that you can go an upvote ;)

这还不受支持。有一个问题,你可以投赞成票;)

优秀答案推荐

    with context.expect_page() as new:
page.evaluate("window.open('https://www.google.com')")
page2 = new.value

page.bring_to_front()
sleep(2)
print(context.pages)
page2.bring_to_front()

更多回答

Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, can you edit your answer to include an explanation of what you're doing and why you believe it is the best approach?

请记住,Stack Overflow不仅仅是为了解决眼前的问题,也是为了帮助未来的读者找到类似问题的解决方案,这需要理解底层代码。这对于我们社区的初学者和不熟悉语法的成员来说尤其重要。考虑到这一点,你能编辑你的答案,包括你正在做的事情的解释以及为什么你认为这是最好的方法吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com