Discovering the login details element with Selenium in Python is a simple task

Currently in the process of learning how to use Selenium with Python. I have been practicing on the BBC website, but I am a bit stuck on adding code for a specific screen. Specifically, I need help with identifying the fields "Email or username" and "Password". I have attached a screenshot to provide more context. This is what my current code looks like:

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:

Answer №1

To input a character sequence into the Email or username field, you will need to use WebDriverWait in order to wait for the element to be clickable with 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: Make sure to include the necessary 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:

https://i.stack.imgur.com/y9H75.jpg

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging selenium for writing messages directly to Chrome's console

Is there a way to write directly to the Chrome console using Selenium and Python? I'm not looking for a solution that involves sending keys to open the console. If direct writing is not possible, are there any libraries or APIs that allow this functio ...

Ways to interact with elements lacking an identifier

Currently, I'm faced with an HTML challenge where I need to interact with an element labeled tasks. *<td class="class_popup2_menuitem_caption" unselectable="on" nowrap="">Tasks</td>* In my attempt to do so, I've implemented the foll ...

What is the rationale behind assigning names to variables in Tensorflow?

During my observation in various locations, I noticed a pattern in variable initialization where some were assigned names while others were not. For instance: # Named var = tf.Variable(0, name="counter") # Unnamed one = tf.constant(1) What is the signif ...

Issue arises when attempting to run npm start on Windows 10 due to node-gyp failing

After setting up Node.js version 12.18.1 and Python v3.8.1 on my Windows 10 system, I encountered an issue when trying to run npm install in a project: gyp ERR! configure error gyp ERR! stack Error: Command failed: C:\Program Files (x86)\Python&b ...

Unable to establish a connection with the python3 service located at /usr/local/bin/geckodriver

Here is the code snippet I am using: #!/usr/bin/python3 from selenium import webdriver driver = webdriver.Firefox(executable_path=r'/usr/local/bin/geckodriver') driver.get('http://www.python.org') The error that I am encountering is ...

Performing a single query in Django to join model attributes using select_related

Seeking an ideal solution to retrieve attributes on a join model with a single query. The models relationships are as follows: class Player(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) ...

python creating a copy of a pandas dataframe with assigned missing values

I'm currently attempting to establish the mean value for a group of products within my dataset. My goal is to iterate through each category and fill in any missing data as needed. df.loc[df.iCode == 160610,'oPrice'].fillna(value=df[df.iCode ...

Optimal method for shuffling a matrix in either R or Python

Currently, I am dealing with a large numeric matrix M in R that consists of 11000 rows and 20 columns. Within this matrix, I am conducting numerous correlation tests. Specifically, I am using the function cor.test(M[i,], M[j,], method='spearman' ...

What is causing the ImportError: No module named apiclient.discovery error in my Python App Engine application utilizing the Translate API?

I encountered an issue in Google App Engine's Python while using Google Translate API, I am unsure how to resolve it, <module> from apiclient.discovery import build ImportError: No module named apiclient.discovery I plan to configure the enviro ...

Developing a TIFFDictionary specific to an image document

My goal is to incorporate a TIFF Dictionary into an image file on my Mac. According to Apple's documentation, the kCGImagePropertyTIFFDictionary defines a dictionary with keys like kCGImagePropertyTIFFXResolution inside it. However, I am struggling t ...

Navigate to precise location using Selenium with Python

Is there a way to scroll down a specific area of a webpage? I'm trying to scroll down on the LinkedIn message section only, not the entire screen. Can someone assist me with this? Please refer to the image for clarification. CLICK HERE ...

Display two separate dataframes in individual visualizations with a common selector/filter option using Altair

I am working with two pandas dataframes called data and data_queue, both having identical structures and containing similar data. My goal is to plot the former as a line chart and the latter as a scatter plot. I require a shared selector that can be used t ...

Convert .docx documents using python-docx to adjust font styles and sizes. Looking to restructure paragraphs within the designated files

In the process of transcribing .docx files, the goal is to change the font and font sizes while preserving attributes like bold, underline, and italic. Additionally, headers and graphics will be incorporated into the target.docx files that are created. Th ...

What is the best way to dynamically retrieve the Firefox profile path using Python?

data_path = "C:\\Users\\Cortex\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\5cfpvg5b.default" Can we determine this file path dynamically? Keep in mind that 5cfpvg5b.default ...

Waiting for a tweet to load before scraping a website using BeautifulSoup, Python, and Selenium

I am currently facing a challenge in scraping a website to extract tweet links, specifically from DW. The issue I'm encountering is that the tweets do not load immediately, causing the request to execute before the page has fully loaded. Despite tryin ...

Having difficulty making a python script compatible with Firefox and Selenium

Hi there, I am struggling to get my Python script working with Firefox and Selenium. When I run the command with pytest, the following error occurs. I am using a VPS Linux Ubuntu to execute this script. pytest /usr/local/bin/ciaobot/ciao.py --indirizzo &q ...

Having trouble locating a webpage using BeautifulSoup based on its URL

Currently, I am utilizing Python along with Selenium for the purpose of extracting all links from the results page of a particular search site. Regardless of what term I enter on the previous screen, the URL for any search conducted on the results page rem ...

CS50 PSET7 Problem: Encountering an Error with Type 'NoneType'

I am experiencing difficulties with the /quote function in PSET 7 of CS50. Each time I access the CS50 finance site, I encounter the following error message: AttributeError: 'NoneType' object has no attribute 'startswith' Understandin ...

What is the best way to tally total distinct values within each group?

Can someone help me figure out how to count cumulative unique values by groups in Python? Here is an example dataframe: Group Year Type A 1998 red A 1998 blue A 2002 red A 2005 blue A 2008 blue A 2008 yello B 1998 red B 2001 red B ...

selenium.getEval() and driver using (JavascriptExecutor) encounter issues with SeleniumException while waiting for the evaluation of evaluate.js in Firefox versions 17 and 19, with webdriver v2.32

Encountered an exception while running JS code on firefox 17.0. The v2.32 changelog states support for 10esr, 17esr, 19, 20, and although the latest webdriver version is 2.35, I'm using v2.32 due to locator issues with certain tests. This setup works ...