给出了错误的硒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
请不要手动输入回溯或重新格式化它们。例如,我怀疑实际的错误可能会说'__init __()'而不是'init()'。 –
需要此解决方案 –
然后在您的报告中确保您**准确**。这个*是由'__init__'方法引起的;这是创建实例时调用的方法。 'presence_of_element_located()'是一个带'__init__'方法的类,它只需要一个'locator',而不是两个参数。 –