0

I'm getting this annoying error with selenium:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="button-submit"]"}

My code:

https://pastebin.com/BS49JibR

Button i'm trying to click with selenium:

https://i.stack.imgur.com/Gl5m1.png

BGMine 13
  • 1
  • 1
  • 2

1 Answers1

1

To click() on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#button-submit[name='submit'][value='valider']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='button-submit' and @name='submit'][@value='valider']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

References

You can find a couple of relevant discussions on NoSuchElementException in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • That didnt work, here's the error \discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "C:\Users\BGMine13\Desktop\discordBotScreen\Discord Screenshot Bot.py", line 48, in on_message WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='button-submit']"))).click() File "C:\Users\BGMine13\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: – BGMine 13 Mar 08 '22 at 15:46
  • @BGMine13 Somehow did you find some time to go through the reference discussions? – undetected Selenium Mar 08 '22 at 15:48
  • Yes, my chrome version is 99.0.4844.51 and chromedriver version is ChromeDriver 99.0.4844.51 – BGMine 13 Mar 08 '22 at 15:52