- from selenium import webdriver
- from selenium.webdriver.chrome.options import Options
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.common.exceptions import TimeoutException
- # Configure Chrome options
- chrome_options = Options()
- chrome_options.add_argument("--headless")
- chrome_options.add_argument("--no-sandbox")
- # Initialize WebDriver
- driver = webdriver.Chrome(options=chrome_options)
- driver.get("https://toolkit.tesco.com/sign-in/")
- try:
- # Locate the login button by its contained text "Sign in"
- login_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//button[contains(text(), "Sign in")]')))
- login_button.click()
- # Locate the email address field by its name attribute
- username_field = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, 'email-address')))
- username_field.send_keys('[email protected]')
- # Locate the password field by its name attribute
- password_field = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.NAME, 'password')))
- password_field.send_keys('Pladmarch11')
- # Submit the form by locating the login button again and clicking it
- login_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//button[contains(text(), "Sign in")]')))
- login_button.click()
- except TimeoutException:
- print("Timeout error: Unable to locate login elements.")
- # Close the WebDriver session
- driver.quit()
[text] h
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: