如何解决 Selenium 中的此错误:错误:无法将 tbsCertificate 读取为序列,错误:解析证书失败

问题描述 投票:0回答:4

我正在尝试在 Python 中执行一个 selenium 程序,以便通过单击当前主页中的按钮转到新的 URL。我是硒的新手,任何有关这方面的帮助将不胜感激。这是我的代码

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

url = 'https://nmit.ac.in'

driver = webdriver.Chrome()

driver.get(url)

try:
    # wait 10 seconds before looking for element
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located(By.LINK_TEXT, "Parent Portal")
    )

except:
    print()

driver.find_element(By.LINK_TEXT, "Parent Portal").click()

我尝试增加等待时间以及使用

BY
关键字下支持的所有形式的定位策略,但无济于事。我不断收到此错误。

python selenium-webdriver web-scraping browser certificate
4个回答
3
投票

我在寻找解决方案时花了很多时间,然后我在这里找到了它。

options = webdriver.ChromeOptions()

options.add_experimental_option('excludeSwitches', ['enable-logging'])

driver = webdriver.Chrome(
    service= Service(chromedriver_path), 
    options=options,
)

driver.get('https://www.google.com/')

它应该消除 selenium 中所有烦人的错误和警告


2
投票

据我所知,您不应该担心这些错误。虽然,我证明了你的代码,但它没有在网页中找到任何元素。我可以建议您使用您想要查找的元素的 xpath:

    # wait 10 seconds before looking for element
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, "/html//div[@class='wsmenucontainer']//button[@href='https://nmitparents.contineo.in/']"))
    )   
    element.click()
    #wait for the new view to be loaded
    time.sleep(10)  
    driver.quit()

Psdt:您可以使用扩展 Ranorex Selocity 提取网页中任何元素的良好且唯一的 xpath 并对其进行测试! image


0
投票

我能够使用以下方法解决它:

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])

0
投票

铬:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging']) # Here
driver = webdriver.Chrome(options=options)

微软边缘:

from selenium import webdriver

options = webdriver.EdgeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging']) # Here
driver = webdriver.Edge(options=options)

火狐。 *

FirefoxOptions()
没有
add_experimental_option()
:

from selenium import webdriver

options = webdriver.FirefoxOptions()
options.accept_untrusted_certs = True # Here
driver = webdriver.Firefox(options=options)
driver.get("https://www.w3schools.com/")
© www.soinside.com 2019 - 2024. All rights reserved.