[*] Введите имя пользователя/пароль (администратор/администратор) и войдите в систему.
[*] Нажмите вкладку WAN в верхней части интерфейса. Вход. />
Код: Выделить всё
py "Modem Refurbishment App/scripts/zte_ppp_selenium.py" \
--ip 192.168.5.1 \
--user admin \
--pass admin \
--headful \
--prelogin-delay-sec 10
Даже если я предоставляю правильные учетные данные, Selenium не выполняет шаг входа в систему. Панель администратора модема остается на странице входа в систему. (Ajax) После входа в систему.
[*] Сценарий предпринимает предприниматели как на основе JS, так и на основе кликов
Дополнительное требование :
При запуске в режиме головы я приостанавливаю заполнение Seleniu Браузер. < /p>
В дополнение к этому, я также хочу иметь возможность увидеть интерфейс после успешного входа в систему, включая меню администратора и последующие этапы навигации внутри браузера, пока сценарий продолжает выполнять. Прошивка модема, которая блокирует логин селена? /> среда < /strong>: < /p>
python 3.x < /li>
selenium 4.x < /li>
Chrome + Matching Chromedriver < /li>
zte zxhn h298a moder, arrdware. Ttn.26_240416 < /li>
< /ul>
Вот более простой пример сценария: < /p>
import time
import os
import tempfile
import logging
import argparse
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
ROUTER_URL = "http://192.168.5.1/"
USERNAME = "admin"
PASSWORD = "admin"
LOGIN_TIMEOUT_SEC = 15
def setup_driver(headless=True):
options = Options()
if headless:
options.add_argument("--headless=new")
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
driver = webdriver.Chrome(options=options) # Selenium Manager auto-downloads driver
return driver
def login(driver, base_url: str, username: str, password: str, pause_before_submit: float = 0.0):
driver.get(base_url)
time.sleep(1)
user_el = driver.find_element(By.ID, "Frm_Username")
pass_el = driver.find_element(By.ID, "Frm_Password")
try:
user_el.clear()
pass_el.clear()
except Exception:
pass
user_el.send_keys(username.strip())
pass_el.send_keys(password.strip())
if pause_before_submit > 0:
logging.info("Pausing %.1fs before submit so you can visually confirm fields...", pause_before_submit)
time.sleep(pause_before_submit)
driver.find_element(By.ID, "LoginId").click()
time.sleep(2)
def verify_login(driver) -> bool:
# Poll for either explicit error or solid success indicators
end = time.time() + LOGIN_TIMEOUT_SEC
had_sid = False
error_visible = False
login_form_visible = True
has_admin_indicators = False
while time.time() < end:
# Cookies
had_sid = any(
(c.get("name", "").upper() == "SID" and c.get("value")) for c in driver.get_cookies()
)
# Page content checks
src = driver.page_source
low = src.lower()
# Login form presence
try:
elem = driver.find_element(By.ID, "Frm_Username")
login_form_visible = elem.is_displayed()
except Exception:
login_form_visible = False
# Error banner must be visible to count (initial banner may be present in DOM by default)
try:
err_el = driver.find_element(
By.XPATH,
"//*[contains(text(),'Kullanıcı') and contains(text(),'şifre') and (contains(text(),'hatalı') or contains(text(),'yanlış'))]",
)
error_visible = err_el.is_displayed()
except Exception:
error_visible = False
# Admin indicators
has_admin_indicators = any(
k in low for k in [
"çıkış",
"logout",
"mainnavigator",
"menu",
"systeminfo",
"wanstatedev",
]
)
# Success: SID + no visible login form OR strong admin indicators
if had_sid and (not login_form_visible or has_admin_indicators):
break
time.sleep(0.5)
# Save diagnostics to a stable path near this script
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
script_dir = os.path.dirname(os.path.abspath(__file__))
out_dir = os.path.join(script_dir, "selenium_debug")
os.makedirs(out_dir, exist_ok=True)
screenshot_path = os.path.join(out_dir, f"login_result_{ts}.png")
html_path = os.path.join(out_dir, f"login_result_{ts}.html")
screenshot_ok = False
html_ok = False
try:
driver.save_screenshot(screenshot_path)
screenshot_ok = os.path.exists(screenshot_path)
except Exception as e:
logging.error("Failed to save screenshot: %s", e)
try:
with open(html_path, "w", encoding="utf-8") as f:
f.write(driver.page_source)
html_ok = os.path.exists(html_path)
except Exception as e:
logging.error("Failed to save HTML: %s", e)
if screenshot_ok:
logging.info("Saved screenshot: %s", screenshot_path)
else:
logging.warning("Screenshot not saved: %s", screenshot_path)
if html_ok:
logging.info("Saved HTML: %s", html_path)
else:
logging.warning("HTML not saved: %s", html_path)
success = had_sid and (not login_form_visible or has_admin_indicators)
if success:
logging.info(
"Login SUCCESS | SID=%s | AdminIndicators=%s | LoginFormVisible=%s",
had_sid,
has_admin_indicators,
login_form_visible,
)
else:
if error_visible and login_form_visible:
logging.warning("Login FAILED due to on-page error | SID=%s", had_sid)
else:
logging.warning("Login NOT confirmed | SID=%s (no error banner)", had_sid)
logging.warning(
"Login NOT confirmed | SID=%s | AdminIndicators=%s | LoginFormVisible=%s",
had_sid,
has_admin_indicators,
login_form_visible,
)
return success
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(levelname)s | %(message)s")
parser = argparse.ArgumentParser(description="ZTE router login verifier (selenium)")
parser.add_argument("--headful", action="store_true", help="Show browser window (disable headless mode)")
parser.add_argument("--router-url", default=ROUTER_URL, help="Router base URL")
parser.add_argument("--user", default=USERNAME, help="Admin username")
parser.add_argument("--passw", default=PASSWORD, help="Admin password")
parser.add_argument("--pause-before-submit", type=float, default=0.0, help="Pause (seconds) after typing credentials, before clicking login")
args, _ = parser.parse_known_args()
driver = setup_driver(headless=(not args.headful))
try:
login(driver, args.router_url, args.user, args.passw, pause_before_submit=args.pause_before_submit)
success = verify_login(driver)
if not success:
raise SystemExit(2)
finally:
driver.quit()
< /code>
Я вижу, что правильное имя пользователя и пароль были введены в качестве администратора в браузере, но браузер не проходит страницу входа в систему. Журналы скриптов говорят, что вход в систему был успешным, но я не могу найти имя пользователя и пароль ГЧП в соответствующих меню. Поэтому я не могу быть уверен, что на самом деле вошел в систему.
Я могу вручную войти с теми же учетными данными. < /P>
Подробнее здесь: https://stackoverflow.com/questions/797 ... rect-crede