Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
This is the error i am getting. I am using the latest version of selenium and python and i am stuck here. any help will be highly appreciated:
Traceback (most recent call last):
File "C:\Users\Moga Road Carrier\PycharmProjects\pythonProject\day1\firstTestCase.py", line 9, in <module>
term = driver.find_element(By.NAME, "username")
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Moga Road Carrier\PycharmProjects\pythonProject\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 861, in find_element
return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Moga Road Carrier\PycharmProjects\pythonProject\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Users\Moga Road Carrier\PycharmProjects\pythonProject\venv\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="username"]"}
# (Session info: chrome=109.0.5414.75)
Stacktrace:
Backtrace:
# (No symbol) [0x0107F243]
# (No symbol) [0x01007FD1]
# (No symbol) [0x00EFD04D]
# (No symbol) [0x00F2C0B0]
# (No symbol) [0x00F2C22B]
# (No symbol) [0x00F5E612]
# (No symbol) [0x00F485D4]
# (No symbol) [0x00F5C9EB]
# (No symbol) [0x00F48386]
# (No symbol) [0x00F2163C]
# (No symbol) [0x00F2269D]
GetHandleVerifier [0x01319A22+2655074]
GetHandleVerifier [0x0130CA24+2601828]
GetHandleVerifier [0x01128C0A+619850]
GetHandleVerifier [0x01127830+614768]
# (No symbol) [0x010105FC]
# (No symbol) [0x01015968]
# (No symbol) [0x01015A55]
# (No symbol) [0x0102051B]
BaseThreadInitThunk [0x75EAFA29+25]
RtlGetAppContainerNamedObjectPath [0x776A7B5E+286]
RtlGetAppContainerNamedObjectPath [0x776A7B2E+238]
This is the code i tried. I am trying to simply send the keys to the input field but i am getting same error again and again:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
serv_obj = Service("C:\\Drivers\\chromedriver_win32\\chromedriver.exe")
driver = webdriver.Chrome(service=serv_obj)
driver.get('https://opensource-demo.orangehrmlive.com/')
driver.maximize_window()
term = driver.find_element(By.NAME, "username")
term.clear()
term.send_keys("Admin")
To send a character sequence to the username field you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
driver.get('https://opensource-demo.orangehrmlive.com/web/index.php/auth/login')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='username']"))).send_keys("Admin")
Using XPATH:
driver.get('https://opensource-demo.orangehrmlive.com/web/index.php/auth/login')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("Admin")
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.