4

I am trying to login in https://www.ecobolsa.com/index.html with Selenium in python3, but the send_keys functions gets me the message:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: headless chrome=78.0.3904.97)

The code is:

from selenium.webdriver.chrome.options import Options
from selenium import webdriver

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")

email = 'fake@gmail.com'
password = 'fakepass3'

driver = webdriver.Chrome('chromedriver', options=options)

driver.get('https://www.ecobolsa.com/index.html')

driver.find_element_by_id("userNameTextBox").send_keys(email)
driver.find_element_by_id("password_login").send_keys(password)

I have tried other solutions but none of them have been successful. I need help.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
jatorna
  • 137
  • 6
  • Summarizing @KunduK's answer, you'll need to tell Selenium to _wait_ for the element to become interactable before you can interact with it. There are a couple of ways to accomplish this: using explicit `time.sleep()`s, using WebDriverWait, or implicit waits. WebDriverWait is probably the "best practice" approach, since it's a built-in Selenium feature (unlike `time.sleep()`) and because implicit waits affect the WebDriver for the life of the WebDriver, i.e. cannot be changed after declared on a driver. – natn2323 Nov 12 '19 at 06:30

2 Answers2

9

You need to do a lot of things to get this work.

  • Need to set windows-size since you are dealing with headless mode.By passing the arguments. options.add_argument("window-size=1920x1080")

    -Need to click ACEPTO button and then click on login link.

    -Induce WebDriverWait And element_to_be_clickable()

Here is the code.

from selenium.webdriver.chrome.options import Options
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
from selenium.webdriver.common.action_chains import ActionChains
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("window-size=1920x1080")

email = 'fake@gmail.com'
password = 'fakepass3'

driver = webdriver.Chrome('chromedriver', options=options)
driver.get('https://www.ecobolsa.com/index.html')
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//button[normalize-space()='ACEPTO']"))).click()
loginlink=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//li[@class='login']/a")))
ActionChains(driver).move_to_element(loginlink).click(loginlink).perform()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"userNameTextBox"))).send_keys(email)
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"password_login"))).send_keys(password)
print('pass')
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • Correct, but why does window-size=1920x1080 fix this? – Nabin Apr 04 '20 at 11:55
  • @Nabin That is because headless browser can’t recognise the fire events without window-size. – KunduK Apr 04 '20 at 13:56
  • So that's true regardless of anything or any scenario? – Nabin Apr 04 '20 at 14:00
  • Most of the cases it will work.However Some scenario where headless browser option block by some of the website to prevent scrapping in that case this solution won’t work.Hope you understood. – KunduK Apr 04 '20 at 14:05
1

To login in within the website https://www.ecobolsa.com/index.html using Selenium you need to:

  • Induce WebDriverWait for:

    • Button with text as ACEPTO to be clickable.
    • Element containing the link to login to be clickable.
    • Username field to be clickable.
  • Code Block:

    options = webdriver.ChromeOptions()
    options.add_argument("window-size=1920x1080")
    options.add_argument("--headless")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://www.ecobolsa.com/index.html")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.qc-cmp-button[onclick]"))).click()
    WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, "div.qc-cmp-ui-container.qc-cmp-showing")))
    ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li.login>a")))).click().perform()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#userNameTextBox"))).send_keys("jatorna")
    driver.find_element_by_css_selector("input#password_login").send_keys("jatorna")
    driver.save_screenshot('./Screenshots/login.png')
    print("Program completed")
    driver.quit()
    
  • Browser Snapshot:

login

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