简体   繁体   English

为什么我收到此错误? selenium.common.exceptions.NoSuchElementException

[英]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

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.是因为您的CSS selector不正确。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “错误:selenium.common.exceptions.NoSuchElementException:消息 - "Error: selenium.common.exceptions.NoSuchElementException: Message selenium.common.exceptions.NoSuchElementException - selenium.common.exceptions.NoSuchElementException Selenium.common.exceptions.NoSuchElementException 错误,即使显式等待 - Selenium.common.exceptions.NoSuchElementException error even with explicit waiting Selenium 中的 selenium.common.exceptions.NoSuchElementException - selenium.common.exceptions.NoSuchElementException in Selenium 如何修复“selenium.common.exceptions.NoSuchElementException” - How can I fix "selenium.common.exceptions.NoSuchElementException" selenium.common.exceptions.NoSuchElementException:消息: - selenium.common.exceptions.NoSuchElementException: Message: 如何修复selenium.common.exceptions.NoSuchElementException? - How to fix selenium.common.exceptions.NoSuchElementException? Selenium 错误 selenium.common.exceptions.NoSuchElementException 尝试通过 ZD22ZCFAC75B2DA745E77 访问 HTML 元素时 - Selenium error selenium.common.exceptions.NoSuchElementException when trying to access an HTML element via Xpath Selenium 使用 Chrome 时出现“selenium.common.exceptions.NoSuchElementException” - Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome selenium.common.exceptions.NoSuchElementException:消息:在使用 Selenium 调用 Instagram 中的关注者链接时,没有此类元素错误 - selenium.common.exceptions.NoSuchElementException: Message: no such element error invoking click on followers link within Instagram with Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM