Answer the question
In order to leave comments, you need to log in
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)
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question