G
G
getrighton2021-09-04 16:08:48
Python
getrighton, 2021-09-04 16:08:48

Why error in python selenium?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome(executable_path='E:/chromedriver.exe')

log_post = ''
pass_post = ''

browser.get('https://mail.rambler.ru/')
time.sleep(5)
mail_find_guard = browser.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/article/form/section[1]/div/div/div/input')
mail_find_guard.send_keys(log_post)
mail = browser.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/article/form/section[2]/div/div/div/input')
mail.send_keys(pass_post)
mail.send_keys(Keys.ENTER)
time.sleep(2)


Mb what's wrong with xpath (yes, I know that they are crooked and it's impossible), but I tried searching both by id and by name.
Error itself:
Exception occurred: NoSuchElementException
Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[1]/div/div/div[1] /article/form/section[1]/div/div/div/input"}
(Session info: chrome=93.0.4577.63)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fxc, 2021-09-05
@fxc

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
browser = webdriver.Chrome(executable_path='E:/chromedriver.exe')

log_post = ''
pass_post = ''

browser.get('https://mail.rambler.ru/')
time.sleep(5)
mail_find_guard = browser.find_element (By.XPATH, '/html/body/div[1]/div/div/div[1]/article/form/section[1]/div/div/div/input')
mail_find_guard.send_keys(log_post)
mail = browser.find_element (By.XPATH, '/html/body/div[1]/div/div/div[1]/article/form/section[2]/div/div/div/input')
mail.send_keys(pass_post)
mail.send_keys(Keys.ENTER)
time.sleep(2)

The idea should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question