Python Selenium新选项卡Microsoft edge
因此,我想使用python selenium模块自动化Microsoft edge。我想使用chrome,但我不知道为什么每当我在pc上打开chrome时,我的pc就会自动关闭,所以我使用Microsoft edge。我了解了如何使用Microsoft edge制作驱动程序以及如何使用Microsoft edge打开网站,但我的问题是如何在新选项卡中显示链接: 要理解我的问题,这里有一些代码:Python Selenium新选项卡Microsoft edge,python,selenium,microsoft-edge,Python,Selenium,Microsoft Edge,因此,我想使用python selenium模块自动化Microsoft edge。我想使用chrome,但我不知道为什么每当我在pc上打开chrome时,我的pc就会自动关闭,所以我使用Microsoft edge。我了解了如何使用Microsoft edge制作驱动程序以及如何使用Microsoft edge打开网站,但我的问题是如何在新选项卡中显示链接: 要理解我的问题,这里有一些代码: from msedge.selenium_tools import Edge, EdgeOptions
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)
链接
是一个列表。你想在不同的标签页中打开吗?是的,我想打开,但这会使它以新的格式出现吗tab@Rohit12345当前位置正在处理它。它是在同一个标签中重新加载的吗?@Rohit12345:试试它对我有用的新代码!你可以用self更改driver
。driver
好的,我不明白为什么睡眠(3)会出错,你能说一下我必须写些什么才能使它适用于课堂吗Driver@Rohit12345:尝试使用时间。改为睡眠(3)