Код: Выделить всё
from time import sleep
from selenium.common import (
ElementNotInteractableException,
StaleElementReferenceException,
)
from selenium.webdriver import Chrome
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from scripts.utils import click_button
driver = Chrome()
timeout = 30
driver.set_page_load_timeout(timeout)
form_values = {
'input[type=email]': 'email',
'input[type=password]': 'password',
}
driver.get('https://mail.google.com')
click_button(
driver, driver.find_element('xpath', '//a[contains(@href, "accounts.google")]')
)
for css, value in form_values.items():
while True:
try:
field = WebDriverWait(driver, timeout).until(
expected_conditions.presence_of_element_located(('css selector', css))
)
field.send_keys(value)
driver.find_element('xpath', '//span[contains(text(), "Next")]').click()
break
except (ElementNotInteractableException, StaleElementReferenceException):
sleep(3)
не удалось войти в систему
Поэтому я пробую тот же подход, используя вместо этого undetected-chromedriver, и иногда это работает, и в большинстве случаев браузер зависает и перестает отвечать после любой отправки или если я вызываю какой-либо из методов селена во время загрузки страницы. Вот версии, используемые в macOS Monterey:
Код: Выделить всё
Chrome 127.0.6533.89
selenium 4.23.1
undetected-chromedriver 3.5.5
Код: Выделить всё
cookies = driver.get_cookies()
session = requests.session()
for cookie in cookies:
session.cookies.set(
cookie['name'], cookie['value'], domain=cookie['domain'], path=cookie['path']
)
response = session.get('https://mail.google.com/mail/u/0')
аккаунт недоступен
....................
Подробнее здесь: https://stackoverflow.com/questions/788 ... n-requests