微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python Selenium 新标签 Microsoft Edge

如何解决Python Selenium 新标签 Microsoft Edge

所以我想使用 python selenium 模块自动化 Microsoft Edge 我想使用 chrome 但我不知道为什么每当我在我的电脑上打开 chrome 我的电脑会自动关闭所以我使用 Microsoft Edge。我想出了如何使用 Microsoft Edge 制作驱动程序以及如何使用 Microsoft Edge 打开网站,但我的问题是如何在新选项卡中显示链接

为了理解我的问题,这里有一些代码

from msedge.selenium_tools import Edge,EdgeOptions


class Driver:
    def __init__(self):
       options = EdgeOptions()
       options.use_chromium = True
       self.driver = Edge(options=options)

    def go_to_link(self,*url):
        for i in url:
            self.driver.get(i)

    def close(self):
        self.driver.close()

    def quit(self):
        self.driver.quit()

links = ["https://www.google.co.in/","https://www.youtube.com/","https://stackoverflow.com/"]
Driver = Driver()
Driver.go_to_link(*links)
Driver.quit()

所以我希望每个链接显示在 Microsoft Edge 的新选项卡中,任何人都可以帮助我吗?

如果有人帮助,如果他们不能,我真的很感激。

解决方法

您可以循环进入所有链接,如下所示:

links = ["https://www.google.co.in/","https://www.youtube.com/","https://stackoverflow.com/"]
number_of_tabs = len(links)
count = 1
for link in links :
  driver.get(link)
  windows_before = driver.current_window_handle
  driver.execute_script("window.open('');")
  #WebDriverWait(driver,10).until(EC.number_of_windows_to_be(number_of_tabs))
  new_window = driver.window_handles[count]
  count = count + 1
  driver.switch_to.window(new_window)
  sleep(3)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。