Amiyanshu
Amiyanshu

Reputation: 1

Why i am getting this error ? selenium.common.exceptions.NoSuchElementException

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

Upvotes: 0

Views: 79

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

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

Upvotes: 1

Related Questions