1

I am trying to automate the login to the following page using selenium: https://services.cal-online.co.il/Card-Holders/SCREENS/AccountManagement/Login.aspx?ReturnUrl=%2fcard-holders%2fScreens%2fAccountManagement%2fHomePage.aspx

Trying to find the elements of username and password using both id, css selector and xpath didn't work.

self._web_driver.find_element_by_xpath('//*[@id="txt-login-username"]')
self._web_driver.find_element_by_id("txt-login-password")
self._web_driver.find_element_by_css_selector('#txt-login-username')

For all three I get NoSuchElement exception

I tried the following JS script: document.getElementById('txt-login-username') when I run this script in selenium or in firefox it returns Null but when I run it in chrome console I get a result I can use. Is there any way to make it work from the python code or to run this on the chrome console itself and not from the python execute_script?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ariel6653
  • 116
  • 1
  • 7

2 Answers2

1

To automate the login to the page using Selenium as the the desired elements are 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 the following solution:

    • Code Block:

      from selenium import webdriver
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.support import expected_conditions as EC
      
      options = webdriver.ChromeOptions()
      options.add_argument("start-maximized")
      driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
      driver.get("https://services.cal-online.co.il/Card-Holders/SCREENS/AccountManagement/Login.aspx?ReturnUrl=%2fcard-holders%2fScreens%2fAccountManagement%2fHomePage.aspx")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='calconnectIframe']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='txt-login-username']"))).send_keys("ariel6653")
      driver.find_element_by_xpath("//input[@id='txt-login-password']").send_keys("ariel6653")
      

Browser Snapshot:

cal-online

Here you can find a relevant discussion on Ways to deal with #document under iframe

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

found a solution to the problem. the problem really was that the object is inside an iframe. I tried to use the solution suggested in Get element from within an iFrame

but got a security error. the solution is to switch frame the follwoing way: driver.switch_to.frame("iframe") and now you can use the normal find elment

ariel6653
  • 116
  • 1
  • 7