2016-11-16 164 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)