【问题标题】:Python Selenium ChromeDriver error. Message: element not interactablePython Selenium ChromeDriver 错误。消息:元素不可交互
【发布时间】:2020-12-21 23:09:19
【问题描述】:

我正在尝试登录 URL。获取元素不可交互错误。

  • 用户名文本框我可以毫无问题地得到它。我这样做: driver.find_element_by_id("id_element").send_Keys("text", Keys.ENTER)
  • 当我得到“元素不可交互错误”时,我需要继续使用不同的范围的密码文本框 driver.execute_script("document.getElementById('password').value 'pass_text'")

最后,当我想提交按钮以进行访问时,我再次收到“元素不可交互错误”。我尝试了这两个范围,但其中任何一个都不起作用。

  1. driver.find_element_by_id("btn_connect").click()
  2. driver.execute_script("document.getElementById('btn_connect').click()")

来自网页的 HTML

<div class="row">
    <div class="col-sm-12 form-group required">
        <label for="username">User name (or email) *</label>
        <div class="field">
            <input type="text" id="username" name="username" autocomplete="username" readonly="">
            <div class="input-group-append">
                <button id="clearUsername" onclick="goToStep1()" type="button" class="btn btn-secondary">X</button>
            </div>
        </div>
    </div>
</div>
<div class="row" id="divPasswordId">
    <div class="col-sm-12 form-group required">
        <label for="password" id="labelPwd">Password *</label>
        <div class="field">
            <input type="password" id="password" name="password" autocomplete="current-password" onchange="onChangePwd(event)" onkeyup="onKeyUpPwd(event)">
        </div>
        <div id="errorMessagesPwd" class="error-messages" style="display: none">This field is required</div>
    </div>
</div>
<div class="row action action-no-border">
    <div class="col-sm-12">
        <ul>
            <li><a onclick="lostIdentifier(getSyUrl('sy-flow-production'))">I have lost my identifier</a></li>
            <li><a onclick="lostPassword(getSyUrl('sy-flow-production'))">I lost my password</a></li>
        </ul>
        <button id="btn_next" name="btn_newt" type="button" class="btn btn-primary pull-right displayNone" onclick="checkIsSsoUser()">
            Next
        </button>
        <button id="btn_connect" name="btn_connection" type="submit" class="btn btn-primary pull-right">
            Login
        </button>
    </div>
</div>

如何解决这个问题?

感谢您的帮助。

【问题讨论】:

  • 您能发布 URL 或示例 HTML 吗?在满足页面上的某些条件之前,按钮/密码字段可能无法交互。
  • @didac 这听起来像X-Y problem。与其寻求解决问题的帮助,不如编辑您的问题并询问实际问题。你想做什么?

标签: python selenium selenium-chromedriver


【解决方案1】:

不要使用ìd 来查找元素,而是尝试使用xpath

driver.find_element_by_xpath("the_xpath_to_the_element")

在 Chrome 中,您可以使用开发人员工具找到您的元素,然后右键单击该元素并单击复制 xpath。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 2022-06-10
    • 1970-01-01
    • 2019-04-19
    相关资源
    最近更新 更多