selenium-webdriver - 使用 Python 执行 Chrome 在 Selenium 中无头,但抛出错误
问题描述
根据这里的答案,我试图让 Chrome 在我的脚本中无头运行。
下面的代码片段在一个名为的函数内,该函数login()
登录到我们的ERP 系统:
if headless == True:
options = Options()
options.headless = True
#Load webdriver
driver = webdriver.Chrome(options=options, executable_path=r'C:/Users/d.kelly/Desktop/Python/chromedriver_win32/chromedriver.exe')
if headless == False:
driver = webdriver.Chrome('C:/Users/d.kelly/Desktop/Python/chromedriver_win32/chromedriver.exe')
window_before_login = driver.window_handles[0]
### Removed Code Block that fills out login form and clicks 'Login' button ###
# Switch to new window ERP (PLEX) launches and close original blank one no longer needed.
window_before_login = driver.window_handles[0]
window_title = driver.title
driver.switch_to.window(window_before_login)
driver.close()
driver.switch_to.window(driver.window_handles[0])
当我这样调用我的函数时:
login(headless=False)
它不会引发任何错误,并且我的整个脚本执行得很好。
当我这样调用我的函数时:
def login(headless=True)
我收到以下错误:
DevTools listening on ws://127.0.0.1:57567/devtools/browser/69f9e357-dccf-4e38-8d6b-78030462379a
[0204/072436.206:INFO:CONSOLE(6)] "Error parsing a meta element's content: ';' is not a valid key-value pair separator. Please use ',' instead.", source: https://test.plexonline.com/modules/systemadministration/login/index.aspx? (6)
[0204/072437.699:INFO:CONSOLE(6)] "Error parsing a meta element's content: ';' is not a valid key-value pair separator. Please use ',' instead.", source: https://test.plexonline.com/Modules/SystemAdministration/Login/Index.aspx (6)
[0204/072437.722:INFO:CONSOLE(1)] "Scripts may close only the windows that were opened by it.", source: (1)
[0204/072441.162:INFO:CONSOLE(751)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.", source: https://test.plexonline.com/Modules/scripts/ajax.js (751)
我正在使用Chrome Version 79.0.3945.130 (Official Build) (64-bit)
,Selenium 3.141.0
和Python 3.7.4
.
任何想法我做错了什么?谢谢!
解决方案
推荐阅读
- go - 指向切片的指针的 Golang 类型断言
- python - Python itemgetter根据值字符串的中间对dict进行排序
- python - 不明白为什么有一个额外的窗口
- php - RelationNotFoundException 调用未定义的关系 Laravel
- javascript - 如何将数据从 vue 中的表格组件传递到另一个表格组件,使用编辑按钮传递表格中的每一行
- database - 如何在 Dropwizard 项目中创建和开始使用嵌入式 Apache Derby 数据库(Angular 7 前端)
- jquery - 在 Jquery 中手动将 K-Dirty 添加到 Kendo Edit Grid
- css - 在另一个 SVG 标记内仅显示带有样式的 SVG 标记
- ios - 苹果目标上 wchar_t 的标志是什么?
- django - 如果对象在视图psql django中只有一个特定值的字段,如何查询它