Here is the website:
https://opensource-demo.orangehrmlive.com/
I tried to login. And I find the username for HTML:
Here is my attempt, but it has the error that the element cannot be located.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
service = Service(r'D:\Softwares\chromedriver.exe')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
url = "https://opensource-demo.orangehrmlive.com"
driver.get(url)
driver.find_element(By.XPATH, "//input[@name='username']")
>Solution :
You need to wait until elements are loaded completely. Use selenium’s Waits feature.
Refer the below code:
url = "https://opensource-demo.orangehrmlive.com"
driver.get(url)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("test")
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Result:
