gpt4 book ai didi

python - 使用 Selenium 时出错 (Python) : Unable to find class in HTML source code

转载 作者:行者123 更新时间:2023-12-05 04:38:56 26 4
gpt4 key购买 nike

我正在学习如何使用 Selenium。我正在做一些测试,但出现了这个错误:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .layout layout-base

我的代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.common.by import By

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
driver.get("https://page.onstove.com/epicseven/global/list/e7en003?listType=2&direction=latest&page=1")
driver.find_element(By.CLASS_NAME,"layout layout-base")

Image of:我尝试使用 find_element 查找的源代码。

我做错了什么?

最佳答案

layout layout-base 是两个用空格分隔的类名值。
要定位此元素,您可以使用以下任何一种方式:

driver.find_element(By.CLASS_NAME,"layout.layout-base")

或者

driver.find_element(By.CSS_SELECTOR,"div.layout.layout-base")

或者

driver.find_element(By.XPATH,"//div[@class='layout layout-base']")

关于python - 使用 Selenium 时出错 (Python) : Unable to find class in HTML source code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70500966/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com