2

I am just learning Selenium using Python. I used BBC web page, however I am not sure how I can add the code for the following screen. All I need is the code to identify the field "Email or username" and "Password". Please see the screenshot. My code looks like this at the moment.

driver.get("https://www.bbc.co.uk/")
driver.find_element(By.XPATH, "//*[@id='header-content']/div[2]/nav/div[1]/div/div[1]/ul[2]/li[1]/a/span[2]").click()
ele = driver.find_element(By.NAME("Email or username"))

Snapshot:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

To send a character sequence to the Email or 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://www.bbc.co.uk/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span#idcta-username"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='username']"))).send_keys("Denny_Thampi")
    
  • Using XPATH:

    driver.get('https://www.bbc.co.uk/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='idcta-username']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("Denny_Thampi")
    
  • 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:

bbc_sign_in

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352