首页 > 解决方案 > 从鼠标悬停选项卡单击硒

问题描述

我用了

quotes = browser.find_element_by_id('CQ')
quotes.click()

但它回来了

Unable to locate element: {"method":"id","selector":"CQ"}

也许我的功能/参数有误。

截屏

标签: pythonpython-3.xseleniumclick

解决方案


由于页面加载的性质,有时需要 Webdriver 等待。尝试等到元素首先显示/启用,然后再单击它。用于 WebDriver 等待的 Python Selenium 文档:http: //selenium-python.readthedocs.io/waits.html

from selenium.webdriver.support import expected_conditions as EC
    wait = WebDriverWait(driver, 10)
    element = wait.until(EC.visibility_of_element_located((By.ID, 'someid')))

推荐阅读