0

Actually my code is simple and the task too, but somehow i get this Error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"TLoginBox"}

I tried any of the find element and find element by options but none did work. All i found out is that on the website where the login button is, that the button itself somehow is a whole HTML with head, body,...

T-online Email Link

That's my code:

from selenium.webdriver.common.by import By
from time import sleep
from selenium import webdriver


browser = webdriver.Chrome('F:/trzttrtz/chromedriver_win32/chromedriver')
browser.get('https://www.t-online.de/themen/e-mail')
sleep(5)
login = browser.find_element(By.ID, value="TLoginBox")
login.click()

I am new to programming, so any help means a lot. Thanks in advance.

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

2 Answers2

0

The element cannot be found because it is inside another frame, try the following:

from selenium.webdriver.common.by import By
from time import sleep
from selenium import webdriver


browser = webdriver.Chrome('F:/trzttrtz/chromedriver_win32/chromedriver')
browser.get('https://www.t-online.de/themen/e-mail')
frame = browser.find_element(By.CLASS_NAME, 'TlgnBoxIfr')
browser.switch_to_frame(frame)
login = browser.find_element(By.CLASS_NAME, value='TlogBtn')
login.click()

If you want to go back to the main frame use:

browser.switch_to().default_content()
Isma
  • 14,604
  • 5
  • 37
  • 51
0

The element with the text as E-Mail Login is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://www.t-online.de/themen/e-mail')
    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.TlgnBoxIfr")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.TlogBtn>span.mailicn>img"))).click()
    
  • Using XPATH:

    driver.get('https://www.t-online.de/themen/e-mail')
    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='TlgnBoxIfr']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='TlogBtn']/span[@class='mailicn']/img"))).click()
    
  • 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:

telekonLogin


Reference

You can find a couple of relevant discussions in:

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