2016-09-22 53 views
0

给出了错误的硒webdriverwait:__init __()究竟需要两个参数(3给出)

Traceback (most recent call last): 
    File "p3.py", line 21, in <module> 
    WebDriverWait(driver, timex).until(EC.presence_of_element_located(by, element)) 
TypeError: __init__() takes exactly 2 arguments (3 given) 

我没有用过__init__()这是为什么错误呢?

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.by import By 
import time 

chrome_path=r"C:\Users\Bhanwar\Desktop\New folder (2)\chromedriver.exe" 
driver =webdriver.Chrome(chrome_path) 
driver.get("https://priceraja.com/mobile/pricelist/samsung-mobile-price-list-in-india") 
#driver.implicitly_wait(10) 
i=0 
timex = 5 
by = By.ID 
hook = "product-itmes-" # The id of one item, they seems to be this plus 
         # the number item that they are 
button = '.loadmore' 
while i<3: 
    element_number = 25*i 
    element=hook+str(element_number)# It looks like there are 25 items added each time, and starts at 25 
    WebDriverWait(driver, timex).until(EC.presence_of_element_located(by, element)) 
    driver.find_element_by_css_selector(button).click() 
    time.sleep(5) # Makes the page wait for the element to change 
    i+=1 
+1

请不要手动输入回溯或重新格式化它们。例如,我怀疑实际的错误可能会说'__init __()'而不是'init()'。 –

+0

需要此解决方案 –

+1

然后在您的报告中确保您**准确**。这个*是由'__init__'方法引起的;这是创建实例时调用的方法。 'presence_of_element_located()'是一个带'__init__'方法的类,它只需要一个'locator',而不是两个参数。 –

回答

2

presence_of_element_located()只需要一个参数,一个定位器,它是一个元组。您忘记在呼叫中添加一个元组所需的(...)圆括号:

WebDriverWait(driver, timex).until(
    EC.presence_of_element_located((by, element))) 
#   these make this a tuple^and  ^
+0

我们是否应该回答印刷错误或关闭它们的问题? –

+0

@PadraicCunningham:不确定这是否是排印问题。如果你认为它是可以投票结束的话。 –

+0

根据http://socvr.org/中的一些人的说法,我们只是应该关闭而不回答,以便它们可以更容易地删除。你是一个国防部,所以我问了这个问题。 –

相关问题