gpt4 book ai didi

python - Selenium webdriverwait : __init__() takes exactly 2 arguments (3 given)

转载 作者:太空宇宙 更新时间:2023-11-04 07:17:01 24 4
gpt4 key购买 nike

给出错误为

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

最佳答案

presence_of_element_located() 只接受一个参数,一个定位器,它是一个元组。您忘记在调用中添加元组所需的 (...) 括号:

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

关于python - Selenium webdriverwait : __init__() takes exactly 2 arguments (3 given),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39636236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com