小编Mub*_*Ali的帖子

元素在 Selenium Chrome 无头模式下不可交互

当我不在无头模式下运行 chrome 时,我的代码工作得很好,但在无头模式下我得到“元素不可交互”。

我在 email_box.send_keys('') 处收到错误

我已经设置了窗口大小,但它仍然不起作用

代码:

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import time

options = Options()
options.add_argument('headless')
options.add_argument('window-size=1366x768')

with Chrome(options=options) as driver:
    driver.get('https://accounts.google.com/login')

    WebDriverWait(driver, 20).until(lambda d: d.find_element(By.TAG_NAME, 'input'))

    time.sleep(2)
    email_box = driver.find_element(By.TAG_NAME, 'input')
    time.sleep(2)
    email_box.send_keys('example@gmail.com')
Run Code Online (Sandbox Code Playgroud)

selenium python-3.x selenium-chromedriver selenium-webdriver google-chrome-headless

9
推荐指数
2
解决办法
9603
查看次数

尝试在 Selenium 中为 google 登录设置 cookie 时,在 ['Strict', 'Lax'] 中断言 cookie_dict['sameSite'] 出现断言错误

with Chrome() as driver:
    driver.get(notebooks[0])

    for cookie in pickle.load(open('cookies.pkl', 'rb')):
        driver.add_cookie(cookie)
Run Code Online (Sandbox Code Playgroud)

我首先通过手动登录转储cookie,但在设置它们时出现此错误。

python selenium setcookie selenium-chromedriver selenium-webdriver

4
推荐指数
1
解决办法
2829
查看次数