TypeError: __init__() takes 2 positional arguments but 3 were given
近日在使用selenium+python3.6爬取一个网站时遇到这个问题:
Traceback (most recent call last):
File "D:/pythoncode/spider/spiderforQA.py", line 17, in <module>
wait=WebDriverWait(driver,10).until(EC.presence_of_element_located(By.XPATH,'//*[@id="heading0"]/a'))
TypeError: __init__() takes 2 positional arguments but 3 were given
该问题的原因是EC.presence_of_element_located()方法传参的问题,往该方法传参数时需要将参数用“()”括起来使其作为一个整体,而不是单独传入。如下所示:
将:WebDriverWait(driver,10).until(EC.presence_of_element_located(By.XPATH,'//*[@id="heading0"]/a'))
修改为:WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,'//*[@id="heading0"]/a')))
就OK!