I have a website where I need to login:
https://gb.clientportal.dunnhumby.com/bkr
I m using Selenium
to do so. When inspecting the page, the login input field has the following attributes:
<input id="userNameInput" name="UserName" type="email" value="" tabindex="1" class="text fullWidth" spellcheck="false" placeholder="someone@example.com" autocomplete="off">
I would use the following:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get('https://gb.clientportal.dunnhumby.com/bkr')
username = driver.find_element(By.CSS_SELECTOR,"#userNameInput")
username.send_keys('test_user')
It returns an error: NoSuchElementException
I tried to find element by all possible options: id
, name
- everything gives an error.
Then I tried the waiting:
driver = webdriver.Chrome()
driver.get('https://gb.clientportal.dunnhumby.com/bkr')
wait = WebDriverWait(driver, 10)
username_field = wait.until(EC.visibility_of_element_located((By.XPATH, '//input[@id="userNameInput"]')))
The error is TimeoutException: Message: Stacktrace:Backtrace:
Like even after waiting the element is still not located.
Then I tried to check iframe
, but there is no iframe
on that URL.
driver.find_element(By.TAG_NAME, "iframe")
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"tag name","selector":"iframe"}
Any ideas what else I can try?
Thanks
There is a FRAME within which the desired element is wrapped. You first need to switch into the FRAME and then perform action. Refer the below working code:
driver.get("https://gb.clientportal.dunnhumby.com/bkr")
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "(//frame)[1]")))
username = driver.find_element(By.CSS_SELECTOR,"#userNameInput")
username.send_keys('test_user')
Imports required:
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Result:
Once actions are performed with the FRAME, you can switch back to main content using below code:
driver.switchTo().defaultContent();
Below is the HTML of the FRAME for your reference: