1

Here is a small test carried out with selenium in python:

 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()

And to call test:

entreprisePage.load(input.name_entreprise)

There's no problem, everything works fine!

Now I have a problem when I try to have a dynamic xpath:

instead of having "//a[@id='company_98']/div/span" I am trying to pass the id.

At the test level I add a new parameter (the integer type id that I have to convert to a string to be able to concatenate the xpath):

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

At the class level I no longer use a locator for the click:

 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()

When running the test I got the following error message:

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

thanks for your help

I've tried to send directly parameters in string format , same problem :

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

1
  • Please provide more code, but it looks like you named a variable in a test suite in such a way that it follows test case naming convention, thus test environment tries to run it as a TC. Commented Aug 2, 2023 at 11:10

1 Answer 1

2

You got an error, because syntax of find_element is not correct.

By.XPATH is a variable, not a function and you try to call it as a function.

This is correct syntax:

self.driver.find_element(By.XPATH, "//a[@id='company_" + id_entreprise + "']/div/span").click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.