TypeError:'str'对象不可调用selenium -

问题描述 投票:0回答:0

这是在 python 中使用 selenium 进行的一个小测试:

 locators = {
        "entreprise_selection": ("ID", 'uidropdownCompanies'),
        "entreprise_load": ("XPATH", "//a[@id='company_98']/div/span"),
        "filter": ("XPATH", '//*[@id="filter"]')


        }

    def load(self, name):
        self.entreprise_selection.click_button()
        self.filter.set_text(name)
        self.entreprise_load.click()

并调用测试:

entreprisePage.load(input.name_entreprise)

没问题,一切正常!

现在当我尝试使用动态 xpath 时遇到问题:

而不是拥有

"//a[@id='company_98']/div/span"
我正在尝试传递 id。

在测试级别,我添加了一个新参数(整数类型 id,我必须将其转换为字符串才能连接 xpath):

entreprisePage.load(input.name_entreprise, input.id_entreprise)

在班级级别,我不再使用定位器进行点击:

 locators = {
        "entreprise_selection": ("ID", 'uidropdownCompanies'),
        "filter": ("XPATH", '//*[@id="filter"]')


        }

    def load(self, name, id_entreprise):
        self.entreprise_selection.click_button()
        self.filter.set_text(name)

        self.driver.find_element(By.XPATH("//a[@id='company_" + str(id_entreprise) + "']/div/span")).click()

运行测试时,我收到以下错误消息:

FAILED tests/web_tests/test_login.py::TestLogin::test_login[input0] - TypeError: 'str' object is not callable 

感谢您的帮助

我尝试过直接以字符串格式发送参数,同样的问题:

entreprisePage.load(input.name_entreprise, "98")

   locators = {
        "entreprise_selection": ("ID", 'uidropdownCompanies'),
        "filter": ("XPATH", '//*[@id="filter"]')


        }

    def load(self, name, id_entreprise):
        self.entreprise_selection.click_button()
        self.filter.set_text(name)

        self.driver.find_element(By.XPATH("//a[@id='company_" + id_entreprise + "']/div/span")).click()

FAILED tests/web_tests/test_login.py::TestLogin::test_login[input0] - TypeError: 'str' object is not callable 

python selenium-webdriver xpath pageobjects
© www.soinside.com 2019 - 2024. All rights reserved.