admin管理员组文章数量:1395015
I'm using Flask to run a local web server and using Selenium with Chrome in headless mode to automate a task via Python.
However, when I run the Selenium script in headless mode, it times out when trying to connect to the local Flask server. I get a timeout error during page loading or element wait.
Interestingly, if I first run the same script in headed mode (i.e., without the --headless flag), it works fine. And once it works in headed mode, running it again in headless mode also works — as if the first headed execution somehow "unlocks" the headless behavior.
My Environment:
Selenium Version : 4.28.1
Python Version : 3.10.11
Python script module import list:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdrivermon.alert import Alert
from selenium.webdrivermon.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdrivermon.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdrivermon.by import By
from selenium.webdriver.remote.webelement import WebElement
from seleniummon.exceptions import NoAlertPresentException
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
Python driver Option cmd:
op = webdriver.ChromeOptions()
op.add_argument("start-fullscreen")
op.add_argument("window-size=1920x1080")
op.add_argument('headless=new')
My question:
Why does headless mode fail on the first run but work after using headed mode once?
Is this related to Chrome caching, user data directories, or network behavior?
What can I do to ensure that headless mode works reliably from the first run?
本文标签:
版权声明:本文标题:python 3.x - Selenium Chrome headless mode times out on first run, but works fine after running in headed mode once – why - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744105247a2591034.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论