【发布时间】:2015-03-11 18:03:44
【问题描述】:
我的任务是编写一个解析器来单击网站上的一个按钮,但我在只单击一个按钮时遇到了问题。以下代码适用于除一个之外的每个按钮。
这里是html: http://pastebin.com/6dLF5ru8
这里是源代码: http://pastebin.com/XhsedGLb
python 代码:
driver = webdriver.Firefox()
...
el = driver.find_element_by_id("-spel-nba")
actions.move_to_element(el)
actions.sleep(.1)
actions.click()
actions.perform()
我收到此错误。
ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
根据 Saifur,我刚刚尝试使用相同元素等待不可见异常:
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, "//input[contains(@id,'spsel')][@value='nba']"))).click()
【问题讨论】:
-
谢谢,我刚试过等待,但它超时了
-
您提供的 html 中没有匹配的类名。您使用了错误的选择器
-
Saifur,我只是尝试编辑。它回到了我第一次发布时的位置。
-
像这样:driver.find_element_by_xpath("//input[contains(@id,'spsel')][@value='nba']")