Home > Blockchain >  TypeError: 'str' object is not callable in selenium python
TypeError: 'str' object is not callable in selenium python

Time:03-25

class Locators:
    def locators(self):
        driver = webdriver.Chrome("C:\\seldriver\\chromedriver.exe")
        driver.get("http://automationpractice.com/index.php")
        driver.maximize_window()
        driver.find_element(By.ID("search_query_top" )).send_keys("T-shirts")
        driver.find_element(By.NAME("submit_search")).click()

i am getting this error while trying to locate an element by simple ID in python-selenium

error

Traceback (most recent call last):
  File "C:/Users/abdul_saboor/PycharmProjects/nopcommerceApp/.pytest_cache/locatorsdemo1.py", line 25, in <module>
    obj_Locators.locators()
  File "C:/Users/abdul_saboor/PycharmProjects/nopcommerceApp/.pytest_cache/locatorsdemo1.py", line 18, in locators
    driver.find_element(By.ID("search_query_top" )).send_keys("T-shirts")
TypeError: 'str' object is not callable

CodePudding user response:

find_element(By.ID("search_query_top" ))

That is incorrect usage. By.ID is not a separate function.

Use this instead:

find_element(By.ID, "search_query_top" )
  • Related