"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does Selenium Throw a "NoSuchElementException" When Locating Elements in Chrome?

Why Does Selenium Throw a "NoSuchElementException" When Locating Elements in Chrome?

Published on 2024-12-23
Browse:848

Why Does Selenium Throw a

"NoSuchElementException" for Chrome with Selenium

Issue

While trying to use Selenium on Chrome to interact with QWOP, an error message consistently appears:

selenium.common.exceptions.NoSuchElementException: 
Message: no such element: Unable to locate element
{"method":"id","selector":"window1"
(Session info: chrome=63.0.3239.108
(Driver info: chromedriver=2.34.522913

Cause

The "NoSuchElementException" is raised because the provided locator, id, fails to uniquely identify the desired element.

Solution

To resolve the issue, replace the locator with one that uniquely identifies the canvas element:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//canvas[@id='window1']"))).click()
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3