1
我對Python和Selenium相當陌生,並且試圖進行一些自動化測試我使用頁面對象模型來設置測試,所以只需要在一個地方更新定位器就可以了。作爲其中的一部分,我設置了一個函數來等待我們的訂閱按鈕。點擊然而,當我調用這個函數,我得到以下錯誤:Python:當元素定位器信息從單獨的文件中提取時,「__init __()需要2個位置參數,但是3個被賦予了」使用Webdriver
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函數如何拉動定位器,但我一直無法找出哪裏出了問題。
任何幫助或指導將不勝感激。
謝謝!這很好。還指出我要了解下一個領域。我很感激幫助。 – wappowers