0

Doing a simple test of a clicking dropdown and seeing if the menu is displayed.

    dropdown_user = self.browser.find_element_by_id('dropdown-user')
    dropdown_user.click()
    expanded = dropdown_user.get_attribute("aria-expanded")
    self.assertTrue= (expanded)
    settings = self.browser.find_element_by_id('dropdown-user-settings')
    self.assertTrue(settings.is_displayed())

Gives me this error when I run the test. I cant figure why settings is a str.

   self.assertTrue(settings.is_displayed())
   TypeError: 'str' object is not callable
2
  • it appears that in this specific case, settings.is_displayed is a string rather than a method. You can validate that by printing the result of type(settings.is_displayed). Commented Apr 19, 2017 at 15:58
  • Thanks for the reply. Printing it actually gives me: <class 'method'> ?!?! Commented Apr 19, 2017 at 16:28

1 Answer 1

2

I can't comment (not enough rep) or I would - could you post the whole stack trace? The line self.assertTrue= (expanded) looks like it could feasibly cause an issue.

Edit: I think you're assigning the value of the variable expanded to self.assertTrue, then when you try to call self.assertTrue you're trying to call a string, rather than a function. Remove the line self.assertTrue=(expanded) and replace it with self.assertEqual(expanded, 'true').

Edit 2 to explain in more depth as requested:

The value of expanded is a string - probably 'true', if your dropdown is expanded.

Writing self.assertTrue=(expanded) is the same (in this case) as writing self.assertTrue=expanded. You're assigning the value of the variable expanded (which is a string) to the variable self.assertEqual - it is no longer a function, it's a string!

self.assertTrue(True) # fine
self.assertTrue=('Woops!') # the value of self.assertTrue is now the 
                           # string 'Whoops!'
print(self.assertTrue)
>'Woops!'
self.assertTrue(True) # you're trying to call a string here
> TypeError: 'str' object is not callable

In python, there's nothing to stop you from assigning any type to any variable, because it's dynamically typed.

Sign up to request clarification or add additional context in comments.

8 Comments

Hi thanks for the reply. I think that is the whole stack trace. Not sure if pytest is hiding anything else. But the whole output is just my code with that error at the bottom
Try removing the line self.assertTrue=(expanded) and re-running - you're assigning the assertTrue function the value of expanded with that line, making it a string rather than a function, causing your error.
Nice find! Commenting out the self.assertTrue=(expanded) works I am a little confused though. Is this and issue with using self.assertTrue twice in one test? Since I want to have both of the test is it impossible?
Commenting here since I can't comment in response to your conversation with Bryan Oakley - printing the value of type(settings.is_displayed) and it being <class 'method'> confirms that settings.is_displayed is not the issue - thats the type you'd expect it to be!
I'll edit my answer again to explain more fully what's going on.
|

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.