簡體   English   中英

Python Selenium ChromeDriver 錯誤。 消息:元素不可交互

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

我正在嘗試登錄 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>

如何解決這個問題?

謝謝你的幫助。

嘗試使用xpath而不是使用ìd來查找元素。

driver.find_element_by_xpath("the_xpath_to_the_element")

在 Chrome 中,您可以使用開發人員工具找到您的元素,然后右鍵單擊該元素並單擊復制 xpath。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM