E
E
Ernest Vardanyan2020-10-24 15:19:34
Python
Ernest Vardanyan, 2020-10-24 15:19:34

Why doesn't it find the element when it exists?

Hello, I wrote a code to simply log in to the insta site, but it does not find the element that is present there, I don’t understand why, or it finds it, but rarely, that is, for example: I found the element and entered the data, I exit the site, run the code again and now he does not see it, gives the following error:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [name="username"]


from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from just import username, password


def A(username,password):
    browser = webdriver.Firefox()
    browser.maximize_window()
    browser.get('https://www.instagram.com/')

    s_username = browser.find_element_by_name('username')
    s_username.clear()
    s_username.send_keys(username)


    s_username = browser.find_element_by_name('password')
    s_username.clear()
    s_username.send_keys(password)


    s_username.send_keys(Keys.ENTER)

    browser.close()
    browser.quit()

A(username,password)

I am attaching a photo showing the element name= 'username'

5f941b5967854574193373.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-10-24
@Ernest123

Make a delay, as most likely the authorization block is loaded later.
It can be trite after: add: time.sleep(5)
browser.get('https://www.instagram.com/')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question