0

This is so weird, I'm trying to log into a website with selenium & webdriver. The CSS selector for email input is #ctrl_pageLogin_login, so I tried to sendkeys to that input but i got this error message:

element not interactable

I tried waiting several seconds , xpath , find by tag name , and i got the same error message each time .

Here is my code :

from selenium import webdriver
browser = webdriver.Chrome()
browser.get("https://www.lpsg.com/login")
browser.find_element_by_css_selector("#ctrl_pageLogin_login").send_keys("email@yahoo.com")

I've been searching for a solution for the past days, hope someone can help.

Machavity
  • 30,841
  • 27
  • 92
  • 100
  • The link in the original message was to a porn site. Please do not direct link to sites containing adult material. – Machavity Dec 13 '20 at 01:51

4 Answers4

1

Your site that you're working on has two same element, only one of them is visible.

You're unlucky that the first element is not the element you're trying to find, so your code always fails (the element you found does not do anything).

I tried your site and wrote below code. I tested, it worked.

import time
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
browser = webdriver.Chrome()
browser.get("https://www.lpsg.com/login")
element = WebDriverWait(browser, 10).until(
        EC.visibility_of_any_elements_located((By.ID, "ctrl_pageLogin_login")))[0]
element.send_keys("email@yahoo.com")
time.sleep(10)
browser.quit()

Here's some tips:

  • Use fluent wait. Read more here: https://selenium-python.readthedocs.io/waits.html#explicit-waits
  • In your case, EC.visibility_of_element_located will not work because your first element will not be visible. Use EC.visibility_of_any_elements_located will return a list of visible elements, then pick the first one by using [0].
  • Try to avoid using class name as locator. Use ID or XPATH. Good XPATH will always locate one element.
jackblk
  • 1,076
  • 8
  • 19
0

Immediately after get() statement, don't use sendKeys() method. Put there a small wait to get website loaded and element. Then use sendKeys method.

If it doesn't work then I would recommend to use Javascript to enter the value.

-1

To send a character sequence to the <input> element you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element_by_css_selector("h2.textHeading +dl.ctrlUnit dd>input.textCtrl#ctrl_pageLogin_login").send_keys("email@yahoo.com")
    
  • Using xpath:

    driver.find_element_by_xpath("//h2[@class='textHeading']//following-sibling::dl[@class='ctrlUnit']//dd/input[@class='textCtrl' and @id='ctrl_pageLogin_login']").send_keys("email@yahoo.com")
    

Ideally to send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "h2.textHeading +dl.ctrlUnit dd>input.textCtrl#ctrl_pageLogin_login"))).send_keys("email@yahoo.com")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[@class='textHeading']//following-sibling::dl[@class='ctrlUnit']//dd/input[@class='textCtrl' and @id='ctrl_pageLogin_login']"))).send_keys("email@yahoo.com")
    
  • 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:

LPSG

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

I will recommend you find the element by xpath or by id. also. there is an extension called chropath (available on chrome and firefox) which is very good ad finding the best xpath.

Wester king
  • 103
  • 1
  • 1
  • 5