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

情到浓时终转凉″ 提交于 2019-11-27 14:50:44

The question you should be asking is not "why is it taking 3 args", but "what is taking 3 args". Your traceback refers to a very specific line in code, and it is there where the problem lies.

According to the Selenium Python docs here, the selenium.webdriver.support.expected_conditions.visibility_of_element_located should be called with a tuple; it is not a function, but actually a class, whose initializer expects just 1 argument beyond the implicit self:

class visibility_of_element_located(object):
   # ...
   def __init__(self, locator):
       # ...

Thus, you need to call the visibility_of_element_located with two nested parentheses:

wait.until(EC.visibility_of_element_located( ( By.CSS_SELECTOR, TWITTER_CAMPAIGNS ) ))

Which means that instead of 3 arguments self, By.CSS_SELECTOR and TWITTER_CAMPAIGNS, the visibility_of_element_located.__init__ will be invoked with just expected 2 arguments: the implicit self and the locator: a (type, expression) tuple.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!