selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:

迈克尔·霍夫曼

我正在尝试编写一个Python脚本,该脚本使用多个帐户登录到Kahoot。我遇到了以下问题:我试图用Selenium定位“输入”按钮,然后单击它。但是我得到了以下信息:selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".enter-button__EnterButton-sc-1o9b9va-0 gSoXKU"} (Session info: chrome=83.0.4103.116)我不知道为什么它不起作用。这是我的代码:

from selenium import webdriver

class kahoot_tab:
    def __init__(self):
        self.driver = webdriver.Chrome(r'C:\Users\...\chromedriver.exe')
        self.driver.get('https://kahoot.it/')

    def enter_pin(self, pin):
        self.driver.find_element_by_name('gameId').send_keys(pin)
        self.driver.find_element_by_class_name('enter-button__EnterButton-sc-1o9b9va-0 gSoXKU').click()

tab1 = kahoot_tab()
tab1.enter_pin('123456')

让我感到沮丧的是,此元素存在,因为这是HTML代码: <button type="submit" value="Submit" class="enter-button__EnterButton-sc-1o9b9va-0 gSoXKU" data-functional-selector="join-game-pin"><span>Enter</span></button>

请帮我!

PS:我也尝试过time.sleep(100)在发送图钉和单击按钮之间进行操作。

朋友

您的目标元素具有多个类名。

enter-button__EnterButton-sc-1o9b9va-0gSoXKU

您无法使用.find_element_by_class_name,因为此方法仅用于单个类名。

相反,对于多个类名,可以使用.find_element_by_css_selector以下值.enter-button__EnterButton-sc-1o9b9va-0.gSoXKU

self.driver.find_element_by_css_selector('.enter-button__EnterButton-sc-1o9b9va-0.gSoXKU').click()

CSS选择器参考

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法使用 Selenium 和 Python 定位元素

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试用selenium单击“下一步”按钮时无法找到元素

chromedriver selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素(XPath)

selenium.common.exceptions.NoSuchElementException:消息:无法找到元素:

selenium.common.exceptions.NoSuchElementException:消息:无法找到元素:// pre / * [not(self :: b)]

selenium.common.exceptions.NoSuchElementException:消息:无法定位元素 [id=""]

selenium.common.exceptions.NoSuchElementException:否这样的元素:无法找到元素,我尝试了此driver.implicitly_wait(20)但不起作用

NoSuchElementException:消息:没有这样的元素:使用Selenium和Python无法找到填充用户名的元素错误

使用 selenium 在文本字段中设置值。selenium.common.exceptions.NoSuchElementException:消息:无法定位元素:

无法找到按钮,selenium.common.exceptions.NoSuchElementException

selenium.common.exceptions.NoSuchElementException:消息:即使 HTML 中存在 ID 和名称,Python selenium 中也没有此类元素错误

selenium.common.exceptions.ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素

如何修复selenium.common.exceptions.NoSuchElementException?

selenium.common.exceptions.ElementClickInterceptedException 问题:消息:元素点击被拦截:

selenium.common.exceptions.ElementNotInteractableException:消息:元素未显示

selenium.common.exceptions.TimeoutException:消息:

selenium.common.exceptions.ElementNotVisibleException:消息:元素无法使用Selenium进行交互

selenium.common.exceptions.NoSuchWindowException:消息:使用Selenium和Python单击iframe中的元素没有此类窗口错误

Python中的Selenium错误-消息:没有这样的元素:无法找到元素

NoSuchElementException:消息:没有这样的元素:在使用Selenium和Python刮擦前20个支架时,无法找到元素错误

selenium.common.exceptions.NoSuchElementException:消息:无法定位元素错误,使用 Selenium Python 将文本发送到 Twitter 中的电子邮件字段

无法理解为什么“ selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互”

selenium.common.exceptions.ElementNotVisibleException:消息:元素当前不可见,因此可能无法与之交互

获取 Selenium 错误 - selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互

selenium.common.exceptions.WebDriverException:消息:尝试使用 Selenium 和 Python 单击元素时无法将数据转换为对象

动态内容中的selenium.common.exceptions.NoSuchElementException

使用Chrome时出现硒“ selenium.common.exceptions.NoSuchElementException”

Selenium.common.exceptions.NoSuchElementException错误,即使显式等待