0

Error :

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"button.btn.btn-large.p-x-2.btn-inverse.xh-highlight"}

Here is the inspect code :

<button type="submit" class="btn btn-large p-x-2 btn-inverse xh-highlight" ng-if="!loggingIn" ng-click="submit();" ng-class="{'btn-inverse': !loginForm.$valid, 'btn-primary': loginForm.$valid}">
              Log In</button>

My Code :

path = "C:/Users/Amiyanshu/Downloads/chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get("https://mrs.vodafone.mantica-solutions.com/login")



def login(id,password):
 email = driver.find_element_by_name("username")
 email.send_keys(id)
 Password = driver.find_element_by_name("password")
 Password.send_keys(password)
 button = driver.find_element_by_css_selector("button.btn.btn-large.p-x-2.btn-inverse.xh- highlight").click()
 print(button)
 pass
jsotola
  • 2,238
  • 1
  • 10
  • 22
Amiyanshu
  • 1
  • 2
  • Does this answer your question? [NoSuchElementException - Unable to locate element](https://stackoverflow.com/questions/39190910/nosuchelementexception-unable-to-locate-element) – Prophet Dec 08 '21 at 07:59

1 Answers1

1

This error

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"button.btn.btn-large.p-x-2.btn-inverse.xh-highlight"}

is because your CSS selector is not correct.

Please use the below code:

try:
    login_btn = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[ng-if='!loggingIn']")))
    login_btn.click()
except:
    print("Could not click on login button")
    pass

You will also need to import:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
cruisepandey
  • 28,520
  • 6
  • 20
  • 38