selenium.common.exceptions.NoSuchElementException:消息:无法找到元素: [英] selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:

查看:220
本文介绍了selenium.common.exceptions.NoSuchElementException:消息:无法找到元素:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用selenium在kahoot.it网页上自动生成大量用户,以使它们出现在类的前面,但是,在尝试访问inputSession项(在其中写入进入游戏的gameID)

I'm trying to automatically generate lots of users on the webpage kahoot.it using selenium to make them appear in front of the class, however, I get this error message when trying to access the inputSession item (where you write the gameID to enter the game)

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.kahoot.it")

gameID = driver.find_element_by_id("inputSession")
username = driver.find_element_by_id("username")

gameID.send_keys("53384")

这是错误:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:
{"method":"id","selector":"inputSession"}

任何帮助将不胜感激! :)

Any help would be much appreciated! :)

推荐答案

可能是竞标条件,在该条件下,find元素在页面上出现之前就在执行。看一下等待超时文档。这是来自文档的示例

Could be a race condition where the find element is executing before it is present on the page. Take a look at the wait timeout documentation. Here is an example from the docs

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

driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )
finally:
    driver.quit()

这篇关于selenium.common.exceptions.NoSuchElementException:消息:无法找到元素:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆