0

Please can anyone explain why my code, below, fails on the line:

emailElem = browser.find_element_by_id("loginemail")

? Up until approx. 2 weeks ago, it worked fine. Note that loginid and passwordid are just arbitrary login details which should be entered into the popup screen.

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

def login():
#
    binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox\firefox.exe')
    browser = webdriver.Firefox(firefox_binary=binary)
#
    browser.get('https://purpleport.com/login.asp')
    time.sleep(10)
    window_main = browser.window_handles[0]
    emailtext = 'loginid'
    pwdtext = 'passwordid'
#
    emailElem = browser.find_element_by_id("loginemail")
    emailElem.send_keys(emailtext)
    passwordElem = browser.find_element_by_id("loginpassword")
    passwordElem.send_keys(pwdtext)
    passwordElem.send_keys(Keys.ENTER)
#
    browser.switch_to.window(window_main)
#
    time.sleep(10)
    main_window = browser.current_window_handle
#
    return browser
#
login()
  • 1
    Could you please include your form html and the full error message? – Zailef May 02 '17 at 10:48
  • The HTML code returned by `https://purpleport.com/login.asp` does not contain that element; looks like the login form is inserted via JavaScript later. Also looks like you are trying to counter that by an arbitrary sleep timeout, which of course is just ”gambling” at this point. – CBroe May 02 '17 at 10:57
  • the reason can be compatibility issue (driver vs browser used) as its working fine on Chrome and Firefox for me – thebadguy May 02 '17 at 11:15
  • Not sure how you have got this working with Chrome, since the code only refers to Firefox? Could anyone please explain the essential difference between driver and browser? I know what a browser is, but what does it mean in Python specifically? – Simon Hannaby May 02 '17 at 11:41
  • @CBroe, do you have any suggestions how best to achieve what I wish to do, namely wait for the flyout/popup to launch, switch focus to it and then fill in the data? – Simon Hannaby May 02 '17 at 12:01

0 Answers0