Seleniumbase TimeoutException 仅当使用脚本中的铬时

Seleniumbase TimeoutException only when using chromium from a script

我有一个 url 登录脚本可以正常工作几天但后来退出了,它使用了 chromium webdriver

driver = webdriver.Chrome('/snap/bin/chromium.chromedriver', options=option)

我可以在没有我的脚本的情况下使用 Firefox 或 Chromium 访问 URL(正常)。或脚本中的 Firefox。 但是在脚本中使用 Chromium,它单击登录按钮并挂起,最终导致超时

selenium.common.exceptions.TimeoutException: Message:

如果我打开一个新选项卡并尝试不使用脚本但手动登录,它仍然挂起。只能在从 selenium 启动的浏览器中登录(在我的目标站点上)。

#!/usr/bin/python3
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from seleniumbase import BaseCase
import time
import random

user_name = 'user'
password = 'password'
list = [
        ]
minptime = 4
maxptime = 24

list_length = len(list)
print('Array length ', list_length)
class MyMeClass(BaseCase):
        def method_a():
                option = webdriver.ChromeOptions()
                option.add_argument('--disable-notifications')
                option.add_argument("--mute-audio")
                driver = webdriver.Chrome('/snap/bin/chromium.chromedriver', options=option)

                driver.get("https://me.com/")
                print(driver.title)
                element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.login-btn.btn-shadow#login-fake-btn[data-testid='login-fake-btn']"))).click()
                driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/form/input[1]').send_keys(user_name)
                driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/form/input[2]').send_keys(password)
                time.sleep(5)
                driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/form/button').click() #button click in question
                time.sleep(8)
                driver.get(url)
                print(driver.current_url)
                return driver
driver = MyMeClass.method_a()

我正在访问的按钮

如何use/unblock在脚本中使用 chromium 中的登录按钮?

试试下面的代码:

包含

wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Log in')]"))).click()

Class 姓名

wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn-login btn-shadow']"))).click()

注意:请将以下导入添加到您的解决方案

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

工作解决方案:

driver.get(" your url ")
wait = WebDriverWait(driver,30)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@id='login-fake-btn']")))
print element.text
element.click()

wait = WebDriverWait(driver,30)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='email']"))).send_keys("Test")
wait = WebDriverWait(driver,30)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='password']"))).send_keys("Test")
element1 = wait.until(EC.presence_of_element_located((By.XPATH, "//div[@id='login-overlay']//div//form//button")))
element1.click()

输出: