0

I am trying to use Selenium in Python to try and log into this website

https://commerce.spscommerce.com/auth/login/

All of the xpath's I have tried were not able to locate the element.

driver = webdriver.Chrome()
driver.get("https://commerce.spscommerce.com/auth/login/")
driver.find_element_by_xpath('//input[@id="username"]').send_keys("test")

I tried using name, type and class but have not been able to locate the element. Here is the HTML I got from inspect element

<input id="username" name="username" type="email" required="" ng-model="ctrl.email" ng-
blur="ctrl.checkEmail($event, ctrl.email)" ng-focus="ctrl.resetEmailBoolean()" autofocus="" 
test="login-username" class="ng-pristine ng-valid ng-not-empty ng-valid-email ng-valid-required ng-touched">

Any Ideas on what path to use to locate the element and send the username/password? Thanks so much for the help.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Ryan Bobber
  • 97
  • 1
  • 1
  • 6

1 Answers1

2

The Email Address field 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://commerce.spscommerce.com/auth/login/')
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://commerce.spscommerce.com/auth-app']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#username"))).send_keys("test")
      
    • Using XPATH:

      driver.get("https://www.nasdaq.com/symbol/msft/interactive-chart?timeframe=5d")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@src, 'edgar-chartiq')]")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='btn hideSmallIR stx-collapsible' and @id='dataTableBtn']/span[text()='Data Table']"))).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:

spscommerce


Reference

You can find a relevant discussion in:

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