Python Selenium Message: Unable to locate element


I am developing a web scraper in python that what it does is to take users and passwords from a database and then go to an external web page and fill out the form to later log in, it works perfect with the first username and password, but when it happens to the second it throws me that the "submit" button can not be located.

Any ideas?

I leave the code that I am using:

# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import MySQLdb

db = MySQLdb.connect(host="", user="root", passwd="", db="seliso")

cursor = db.cursor()

cursor.execute("SELECT * FROM usuarios")

for row in cursor.fetchall():
    rfc = row[1]
    clave = row[2]

    driver = webdriver.Firefox()

    username = driver.find_element_by_name("Ecom_User_ID")
    password = driver.find_element_by_name("Ecom_Password")


    submit = driver.find_element_by_name("submit")


    link = driver.find_element_by_link_text("Buzón tributario")



asked by Gustavo Serna 12.07.2016 в 21:34

1 answer


I have often encountered the problem you describe. The reason why you do not see the element in case you are not identifying it wrong, is that you have not given time to load the entire site and build the html from the code that defines it.   There are many efficient solutions, including classes from the library of selenium but in my particular case I usually resolve the issue waiting one or two seconds after the page is loaded

import time

# Todo tu código...

# Haces tiempo para que se forme el contenido del html y sea "visible"

# Continúas con tu código
username = driver.find_element...

I hope I have helped. Greetings!

answered by 25.01.2017 в 16:05