我正试图通过geckodriver加载多个网站标签,并且只有在按如下方式加载这些标签时我才成功:
import time
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.google.com/')
time.sleep(2)
driver.execute_script("window.open('');")
time.sleep(2)
driver.switch_to.window(driver.window_handles[1])
driver.get('https://yahoo.com/?p=us')
driver.execute_script("window.open('');")
time.sleep(2)
driver.switch_to.window(driver.window_handles[2])
driver.get('https://youtube.com')
但是当我尝试加载这样的配置文件时:
import time
from selenium import webdriver
profile_path = (<path to profile folder>)
profile = webdriver.FirefoxProfile(profile_path)
driver = webdriver.Firefox(profile)
driver.get('https://www.google.com/')
time.sleep(2)
driver.execute_script("window.open('');")
time.sleep(2)
driver.switch_to.window(driver.window_handles[1])
driver.get('https://yahoo.com/?p=us')
driver.execute_script("window.open('');")
time.sleep(2)
driver.switch_to.window(driver.window_handles[2])
driver.get('https://youtube.com')
网站在不同的窗口打开。如何在一个窗口上打开它们,同时还能加载配置文件?