我打开10标签(相同的网址)在铬浏览器成功。但问题是,我的网址需要1分钟加载页面,我不想等待1分钟,在每个标签。
我需要让它加载,并希望打开另一个选项卡,我知道最终选项卡强制需要一分钟加载,但没有问题,但我不想等待1分钟,为每个选项卡。
我可以做些甚么来达到这个目标呢?
我用过time.sleep()
,WebDriverWait
,driver.switch_to.window(x)
,但是没有用。
提前致谢
这是我的代码:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common import window
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
url = 'http://my_url/Index'
driver.get(url)
for _ in range(10):
driver.get(url)
driver.switch_to.new_window(window.WindowTypes.TAB)
3条答案
按热度按时间lc8prwob1#
看起来每次打开URL时都需要创建一个线程
gt0wga4j2#
要摆脱等待打开的标签页加载的状态,您需要应用
NONE
PageLoadStrategy
。默认情况下使用NORMAL
PageLoadStrategy
。根据定义,在本例中为WebDriver should wait for the document readiness state to be "complete" after navigation
,而您需要WebDriver should not wait on the document readiness state after a navigation event
策略。要将此
PageLoadStrategy
应用于您的代码,应将此添加到您的代码中:这是我这边整个代码的样子。它按预期工作
hmae6n7t3#
使用Python Selenium打开一个/多个新选项卡而不等待当前选项卡页面加载的最快方法是使用 execute_script() 方法,如下所示: