Python:“__init__() 接受 2 个位置参数,但给出了 3 个”与 Webdriver,当从单独的文件中提取元素定位器信息时
Python: "__init__() takes 2 positional arguments but 3 were given” with Webdriver, when the element locator info is pulled from a separate file
我对 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
我已经阅读了这里和其他网站上的许多相关帖子,虽然它们帮助我更接近于解决问题,但我仍然遇到上述错误。相关代码如下,它来自两个单独的文件,因为定位器与页面对象位于不同的文件中。
page.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)))
locators.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))
我对 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
我已经阅读了这里和其他网站上的许多相关帖子,虽然它们帮助我更接近于解决问题,但我仍然遇到上述错误。相关代码如下,它来自两个单独的文件,因为定位器与页面对象位于不同的文件中。
page.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)))
locators.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))