简体   繁体   English

Python Selenium ChromeDriver 错误。 消息:元素不可交互

[英]Python Selenium ChromeDriver error. Message: element not interactable

I'm trying to login in a URL.我正在尝试登录 URL。 Getting element not interactable as error.获取元素不可交互错误。

  • The username textbox I can get it without any issue.用户名文本框我可以毫无问题地得到它。 I do it like: driver.find_element_by_id("id_element").send_Keys("text", Keys.ENTER)我这样做: driver.find_element_by_id("id_element").send_Keys("text", Keys.ENTER)
  • The password textbox I need to proceed with a different scope as I get the "element not interactable error" driver.execute_script("document.getElementById('password').value 'pass_text'")当我收到“元素不可交互错误” driver.execute_script("document.getElementById('password').value 'pass_text'")

Finally when I want to submit the button to access I get again the "element not interactable error".最后,当我想提交按钮以访问时,我再次得到“元素不可交互错误”。 I tried with the two scopes but either of them don't work.我尝试了这两个范围,但其中任何一个都不起作用。

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

HTML from the webpage来自网页的 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>

How to fix this issue?如何解决这个问题?

Thanks for any help.谢谢你的帮助。

Instead of using the ìd to find an element, try using the xpath .尝试使用xpath而不是使用ìd来查找元素。

driver.find_element_by_xpath("the_xpath_to_the_element")

In Chrome you can just use the developer tools to find your element and then right click on the element and click on copy xpath.在 Chrome 中,您可以使用开发人员工具找到您的元素,然后右键单击该元素并单击复制 xpath。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM