【问题标题】:Seleniumbase TimeoutException only when using chromium from a scriptSeleniumbase TimeoutException 仅在使用脚本中的 chromium 时
【发布时间】:2020-07-28 21:23:14
【问题描述】:

我有一个使用 chromium 网络驱动程序的 url 登录脚本,它运行了几天但后来退出了

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 中使用此登录按钮?

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver chromium


    【解决方案1】:

    试试下面的代码:

    包含

    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()
    

    输出:

    【讨论】:

    • 我都试过了。两人都找到了按钮并按下它,但没有发生登录。和以前一样。
    • 点击预期按钮后出现什么错误?
    • 与帖子中完全相同的超时
    • 你能分享你的网址吗?我认为您的页面加载时间过长,因此它会抛出 TimeoutException。
    • 我可以同时打开 2 个或更多浏览器登录它。我可以使用 firefox 运行脚本,并且可以正常登录。我可以在没有脚本的情况下使用 chromium 并且可以正常登录。但是在铬中“使用脚本”会一直挂起,直到超时。在脚本启动的浏览器中打开第二个选项卡也无法手动执行。我必须先关闭脚本并关闭浏览器才能登录。 bpa.st/IEQQ
    猜你喜欢
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多