简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM