pythonseleniumselenium-webdriverfindelement

what is the solution for this the bug:


This is the code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

s=Service("C:\selenium driver\chromedriver.exe")
driver = webdriver.Chrome(service=s)

driver.get("https://www.selenium.dev/selenium/web/web-form.html")

driver.implicitly_wait(5)

submit_button = driver.find_element(By.CLASS_NAME, "btn btn-outline-primary mt-3")
submit_button.click()

This is the error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn btn-outline-primary mt-3"}
  (Session info: chrome=109.0.5414.120)

Solution

  • btn btn-outline-primary mt-3 -- Because there are blank spaces between the words of class name, it is not able to locate the element.

    Try by XPath instead:

    submit_button = driver.find_element(By.XPATH, "//*[@class='btn btn-outline-primary mt-3']")