当我尝试运行下面的代码时出现错误。
Error is
ElementNotInteractableException:消息:元素不可交互
(会话信息:headless chrome=83.0.4103.116)
这似乎是因为chromeOptions.add_argument("--headless")
。如果我们使用这个参数,我们如何检查元素?请注意,代码中提供的网站名称是虚拟的。
还有一种方法可以在现有打开的浏览器实例中打开网页,而不是使用新的浏览器实例吗?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
chromeOptions=Options()
chromeOptions.add_argument("--ignore-certificate-errors")
chromeOptions.add_argument("--incognito")
chromeOptions.add_argument("--headless")
driver = webdriver.Chrome(executable_path=r"C:/Users/lenovo/Downloads/chromedriver_win32/chromedriver.exe",options=chromeOptions)
driver.get("https://abcd.com")
ele=driver.find_element_by_name('q')
time.sleep(10)
ele.clear()
尝试设置窗口大小以及无头。添加这个:
chromeOptions.add_argument("--window-size=1920,1080")
无头浏览器的默认大小很小。如果代码在未启用 headless 时有效,可能是因为您的对象位于窗口之外。
[编辑 - 更新了以上不起作用的反馈]
回答你的问题而不是尝试解决你的问题。
将其添加到您的选项中:
--remote-debugging-port=9222
或者在本地运行 chrome(不带 chromedriver):
chrome --headless --remote-debugging-port=9222 --disable-gpu https://www.google.com
然后打开一个新的chrome(或选项卡)并转到http://localhost:9222/
You'll get a link to open your page - click on that you'll get devtools for that remote instance:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)