我正在尝试使用selenium在kahoot.it网页上自动生成大量用户,以使它们出现在类的前面,但是,当我尝试访问inputSession项时(在其中写入gameID进入游戏)
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"}
任何帮助将非常感激!:)
可能是竞标条件,在该竞标条件下find元素在页面上出现之前就已执行。看一下等待超时文档。这是文档中的示例
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()