簡體   English   中英

Python - 缺少 1 個參數,即使我提供了它

[英]Python - Missing 1 argument even though I'm providing it

我提供了論據,但我仍然收到錯誤。 我什至嘗試將其作為字符串提供。

錯誤:

C:\anaconda3\python.exe C:/Test/browser_automation/app.py
Enter the author you'd like quotes from: test
test
Traceback (most recent call last):
  File "C:/Test/browser_automation/app.py", line 14, in <module>
    page.select_author(author)
TypeError: select_author() missing 1 required positional argument: 'author_name'

Process finished with exit code 1

應用程序.py

from selenium import webdriver

from pages.quotes_page import QuotesPage

chrome = webdriver.Chrome(executable_path="c:\\Test\\chromedriver.exe")
chrome.get('http://quotes.toscrape.com/search.aspx')
page = QuotesPage(chrome)


author = input("Enter the author you'd like quotes from: ")
print(author)
page.select_author(author) ## Still reports error
#page.select_author('author')  ## Tried it as a string as well and it still reports error.

quotes_page.py 部分內容:

    @property
    def select_author(self, author_name: str):
        self.author_dropdown.select_by_visible_text(author_name)

quotes_page.py 完整文件:

from typing import List
from selenium.webdriver.support.ui import Select

from locators.quotes_page_locators import QuotesPageLocators
from parsers.quote import QuoteParser


class QuotesPage:
    def __init__(self, browser):
        self.soup = browser

    @property
    def quotes(self) -> List[QuoteParser]:
        # locator = QuotesPageLocators.QUOTE
        # quote_tags = self.browser.select(locator)
        # return [QuoteParser(e) for e in quote_tags]
        # return [QuoteParser(e) for e in self.soup.select(QuotesPageLocators.QUOTE)]
        return [
            QuoteParser(e) for e in self.browser.find_elements_by_css_selector(
                QuotesPageLocators.QUOTE
            )
        ]

    @property
    def author_dropdown(self) -> Select:
        element = self.browser.find_elements_by_css_selector(
            QuotesPageLocators.AUTHOR_DROPDOWN
        )
        print(element)
        return Select(element)

    @property
    def select_author(self, author_name: str):
        self.author_dropdown.select_by_visible_text(author_name)

屬性 ( @property ) 方法不能接受任何 arguments

因此,將您的財產從

@property
def select_author(self, author_name: str):
   self.author_dropdown.select_by_visible_text(author_name)

def select_author(self, author_name: str):
    self.author_dropdown.select_by_visible_text(author_name)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM