小编Nic*_*haw的帖子

Python NameError:未使用Selenium定义名称"ElementNotVisibleException"

为什么我使用Python和Selenium收到此错误,我该如何解决?

NameError: name 'ElementNotVisibleException' is not defined
Run Code Online (Sandbox Code Playgroud)

在Python3.5中运行本教程http://www.marinamele.com/selenium-tutorial-web-scraping-with-selenium-and-python中的以下脚本时会发生这种情况

import time
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
from selenium.common.exceptions import TimeoutException


def init_driver():
    driver = webdriver.Firefox()
    driver.wait = WebDriverWait(driver, 5)
    return driver


def lookup(driver, query):
    driver.get("http://www.google.com")
    try:
        box = driver.wait.until(EC.presence_of_element_located(
            (By.NAME, "q")))
        button = driver.wait.until(EC.element_to_be_clickable(
            (By.NAME, "btnK")))
        box.send_keys(query)
        try:
            button.click()
        except ElementNotVisibleException:
            button = driver.wait.until(EC.visibility_of_element_located(
                (By.NAME, "btnG")))
            button.click()
    except TimeoutException:
        print("Box or Button not found in google.com") …
Run Code Online (Sandbox Code Playgroud)

python selenium python-3.x

3
推荐指数
1
解决办法
2099
查看次数

标签 统计

python ×1

python-3.x ×1

selenium ×1