Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: 'str' object is not callable in selenium python

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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" )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading