Search code examples
pythonselenium-webdriverselenium-chromedriver

Cannot get button element of Website in python


I am using the Selenium API and Python. Trying to get a button element of a website. The element is this:

<button class="bg-gray-600 hover:bg-gray-800 items-center font-semibold text-white rounded-r-md px-5 py-3" type="submit">Chat</button>. 

My code:

button = driver.find_elements(By.CSS_SELECTOR(".flex-grow block w-full rounded-l-md border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-gray-600 sm:leading-6"))

I tried to use CSS_SELECTOR on both the element's class and type. But both don't work. They give me the error: 'str' object is not callable


Solution

  • You're not using the correct method to find the element. I can see you are using elements are you using any loop ? if not than the below will work you try this:

    from selenium.webdriver.common.by import By
    
    button = driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]')
    

    if you are using loop than use below

    button = driver.find_elements(By.CSS_SELECTOR, 'button[type="submit"]')