0

Why would selenium not find the element using xpath?

<input class="btn btn-success" name="submit" id="loginButton" accesskey="l" value="Login" tabindex="6" type="submit">

Using:

driver.find_element_by_xpath("//input[@class='btn btn-success']").click()

I get:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //input[@class='btn btn-success']

Tried css selector as well

3
  • 1
    Either you might be trying to click it before it loads, or it may be in an iframe. Have you tried with explicit wait for the element? Commented May 8, 2020 at 22:05
  • @supputuri you are right, I did time.sleep(5) and it clicked.. Good catch Commented May 8, 2020 at 22:10
  • I would prefer explicit wait as mentioned in my below answer rather hard coded, time.sleep Commented May 8, 2020 at 22:28

2 Answers 2

1

Try with explicit wait.

WebDriverWait(driver, 10).until(EC.presence_of_element_located(By.CSS_SELECTOR,"input.btn.btn-success")).click()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the idea, this one worked for me best, WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//input[@class='btn btn-success']"))).click()
0

Try another attribute

driver.find_element_by_xpath("//input[@id='loginButton']").click()

Comments

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.