硒去除:消息:元素不可见

  • 本文关键字:元素 消息 python selenium
  • 更新时间 :
  • 英文 :


我尝试打开 url 并填写登录名和 pwd 并从中打开它。我使用

driver = webdriver.Chrome()
driver.get(auth_url)
login = driver.find_element_by_name("login")
login.send_keys(login)
pwd = driver.find_element_by_name("passwd")
pwd.send_keys(pwd)
btn = driver.find_element_by_class_name('button2 button2_theme_action button2_size_m button2_type_submit i-bem')
btn.click()

但是我得到错误

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible

html-code看起来像

<input class="input__control" id="uniq14963212287341158594" name="login" placeholder="Логин" aria-labelledby="labeluniq14963212287341158594 hintuniq14963212287341158594" aria-required="true"></span></span></div><div class="auth__password"><span class="input input_theme_normal input_size_m i-bem" data-bem='{"input":{"live":false}}'><label class="input__hint input__hint_fallback_yes input__hint_visibility_visible" id="hintuniq14963212287341158595" for="uniq14963212287341158595" aria-hidden="true">Пароль</label><span class="input__box"><span class="input__clear" unselectable="on">&nbsp;</span><input class="input__control" id="uniq14963212287341158595" name="passwd" placeholder="Пароль" aria-labelledby="labeluniq14963212287341158595 hintuniq14963212287341158595" type="password" maxlength="256" aria-required="true"></span></span></div><div class="auth__row auth__row_button_yes"><div class="auth__haunter"><span class="checkbox checkbox_theme_normal checkbox_size_m i-bem" data-bem='{"checkbox":{"live":false}}'><button class="button2 button2_theme_action button2_size_m button2_type_submit i-bem" data-bem='{"button2":{"_tabindex":"0"}}' type="submit" autocomplete="off" tabindex="0"><span class="button2__text">Войти</span></button></div></div><div class="auth__social" role="group" aria-label="Войти при помощи социальной сети"></div><div class="auth__row"><div class="auth__remember"><a class="button2 button2_theme_pseudo button2_size_s button2_type_link i-bem" data-bem='{"button2":{"_tabindex":"0"}}' tabindex="0" href="https://passport.yandex.ru/restoration"><span class="button2__text">Вспомнить пароль</span></a></div><div class="auth__register"><a class="button2 button2_theme_pseudo button2_size_s button2_type_link i-bem" data-bem='{"button2":{"_tabindex":"0"}}' tabindex="0" href="https://passport.yandex.ru/registration"><span class="button2__text">Регистрация</span></a></div></div>

如果等待时间不能解决您的问题,有时我使用以下方法解决它:

driver.set_window_size(1920, 1080)

或者更大,我伸手使用 (4096, 3112(

在执行发送密钥之前添加等待时间

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait
    driver.set_window_size(1920, 1080)
    wait = WebDriverWait(wd, 10)
    login = wait.until(EC.element_to_be_clickable((By.NAME, "login")))
    login.send_keys(login)

那么密码也一样!!

请参考此文档

希望这有帮助!!

我不相信 find_element_by_class_name(( 会处理完整的类名列表。 尝试只指定其中之一。 它在您的 HTML 中看起来是独一无二的:

btn = driver.find_element_by_class_name('button2_theme_action')

相关内容

最新更新