0

enter image description here

I am getting following error

no such element: Unable to locate element: {"method":"xpath","selector":"//input[@placeholder='User ID']"}
  (Session info: chrome=78.0.3904.70). Let me know how can i pass user id here
2
  • 1
    Several things can be going wrong here. You could have multiple input elements located by the XPath -- if you are just using find_element, this may cause an issue. Another issue is the element being nested in an iframe element higher up in the DOM. Without the URL or full HTML for the page you are testing, this problem will be difficult to solve. Commented Oct 29, 2019 at 18:54
  • Please read why a screenshot of code is a bad idea. Paste the code and properly format it instead. Commented Oct 29, 2019 at 19:01

1 Answer 1

2

Without additional context, I can only recommend that you wait on the element before sending keys to it:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


input = WebDriverWait(driver, 30).until(
        EC.visibility_of_element_located((By.XPATH, "//input[@placeholder='User ID']")))

input.send_keys("userId")

Full working sample as requested by asker:

from selenium import webdriver
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()

driver.get("https://kite.zerodha.com/connect/login?api_key=b8w63qg9m4c3zubd&sess_id=bW3U1OwidO97o11scfeTbyfX4j5tViNp")

input = WebDriverWait(driver, 30).until(
        EC.visibility_of_element_located((By.XPATH, "//input[@placeholder='User ID']")))

input.send_keys("userId")

sleep(10) # this sleep is here so you can visually verify the text was sent.

driver.close()
driver.quit()

The above code has succeeded every time I have run it.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Christine, Below is the URL link browser.get('kite.zerodha.com/connect/…) input = WebDriverWait(browser, 10).until( EC.presence_of_element_located((By.XPATH, "//input[@placeholder='User ID']"))) input.send_keys("XXXXX"), ur code worked 1 out 5 tries, rest of times i got time out error
@AravindRajReddy as you can see Christine's answer worked but you should just add a longer wait... WebDriverWait(browser, 30) that should do the trick! good answer.
It fails after 30 seconds browser.get('kite.zerodha.com/connect/…) input = WebDriverWait(browser, 30).until( EC.presence_of_element_located((By.XPATH, "//input[@placeholder='User ID']"))) input.send_keys("XXX") Traceback (most recent call last): EC.presence_of_element_located((By.XPATH, "//input[@placeholder='User ID']"))) File "C:\Users\aarthisastha\Anaconda3\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) TimeoutException
Interesting that the code is only working sometimes, but not other times. If it works once, it's the correct solution, but may need to be configured differently -- you could try experimenting by changing presence_of_element_located to visibility_of_element_located and, as @MosheSlavin has mentioned, increasing the wait time. After looking at your page HTML, there are no other special cases interfering with the element, so the wait.until should be all you need. I've updated my solution with a different wait for you to try.
@AravindRajReddy I have tested my code in my own environment and it has successfully located User ID 5 times in a row. I believe changing presence_of_element_located to visibility_of_element_located helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.