Python:"__init__() 使用 Webdriver 需要 2 个位置参数,但给出了 3 个",当元素定位器信息从单独的文件中提取时



我是Python和Selenium的新手,正在尝试对我们的网站进行一些自动化测试。我使用页面对象模型设置测试,这样对定位器的更改只需要在一个地方更新。作为其中的一部分,我正在设置一个功能,等待我们的订阅按钮可以点击。然而,当我调用这个函数时,我会得到以下错误:

Traceback (most recent call last):
File "click_subscribe_button_test.py", line 51, in test_subscribe_click
main_page.wait_subscribe_button_clickable()
File "page.py", line 64, in wait_subscribe_button_clickable
wait.until(EC.element_to_be_clickable((*MainPageLocators.subscribe_button)))
TypeError: __init__() takes 2 positional arguments but 3 were given

我在这里和其他网站上读了很多相关的帖子,虽然它们帮助我更接近于解决这个问题,但我仍然遇到了上述错误。相关代码如下,它来自两个独立的文件,因为定位器与页面对象位于不同的文件中。

页面.py

def wait_subscribe_button_clickable(self):
subscribeElement =  self.driver.find_element(*MainPageLocators.subscribe_button)
wait = WebDriverWait(self.driver,20)
wait.until(EC.element_to_be_clickable((*MainPageLocators.subscribe_button)))

定位器.py

class MainPageLocators (object):
subscribe_button = (By.CSS_SELECTOR, 'li.last.leaf.subscribe')

问题似乎是我从一个单独的文件中提取定位器的方式,因为如果我更改

wait.until(EC.element_to_be_clickable((*MainPageLocators.subscribe_button)))

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'li.last.leaf.subscribe')))

代码按预期工作。

关于*MainPageLocators.subscribe_button函数是如何拉动定位器的,我可能有些不理解,但我一直无法找出问题所在。

如有任何帮助或指导,我们将不胜感激。

只是根本不解压定位器,按原样将其作为元组传递:

wait.until(EC.element_to_be_clickable(MainPageLocators.subscribe_button))

相关内容

最新更新