仅当从脚本使用chromium时出现Seleniumbase TimeoutException

eqqqjvef  于 2023-01-17  发布在  其他
关注(0)|答案(1)|浏览(105)

我有一个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()

我正在访问的按钮

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

q9rjltbz

q9rjltbz1#

请尝试以下代码:

    • 包含**
wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Log in')]"))).click()
    • 类名**
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()
    • 输出:**

相关问题