2016-11-16 136 views
0

导入我使用Python硒版本3.0.1中似乎与其说蟒蛇硒TIMEUNIT - 从哪里

driver.implicitly_wait(10) 

我们现在必须说

driver.implicitly_wait(10, TimeUnit.SECONDS) 

这给了我错误...

NameError:名字 'TIMEUNIT' 没有定义

所以我需要导入TimeUnit,但是哪里(哪个模块)可以导入?

文档链接https://pypi.python.org/pypi/selenium带我到硒2文档,并在搜索框中键入TimeUnit绘制一个空白。因此,任何想告诉我阅读文档的人都需要告诉我哪些文档是正确的。

+0

为什么你认为'implicitly_wait()'应该需要两个参数? – Andersson

回答

0

我不知道TimeUnit.SECONDS是什么,但无论它是什么implicitly_wait()只有一个参数!

>>> help(driver.implicitly_wait) 
Help on method implicitly_wait in module  selenium.webdriver.remote.webdriver: 

implicitly_wait(time_to_wait) method of  selenium.webdriver.firefox.webdriver.Web 
Driver instance 
Sets a sticky timeout to implicitly wait for an element to be found, 
    or a command to complete. This method only needs to be called one 
    time per session. To set the timeout for calls to 
    execute_async_script, see set_script_timeout. 

:Args: 
- time_to_wait: Amount of time to wait (in seconds) 

:Usage: 
    driver.implicitly_wait(30) 

所以,如果你尝试发送任意2个参数,你应该得到

TypeError: implicitly_wait() takes 2 positional arguments but 3 were given

附:也不要忘了,在这种情况下,第一个位置参数是self是指本身反对

0
from selenium import webdriver 
from selenium.webdriver.support.wait import WebDriverWait 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.common.exceptions import NoSuchElementException 
import time 

driver = webdriver.Firefox() 
driver.get(url) 
driver.implicitly_wait(10)