2016-02-14 58 views
1

我使用硒的Python綁定。嘗試選擇和操作元素時出現以下錯誤。 (使用Chromedriver)蟒蛇硒返回元素不是交互的錯誤

Message: invalid element state: Element is not currently interactable and may not be manipulated 

我認爲該元件可以成功地與下面的語法選自:但我不能操縱它,例如,清除()或send_keys(「某一值」)。我想填寫文本區域,但我無法使其工作。如果您遇到類似問題,請分享您的想法。謝謝。

更新:我注意到HTML正在改變,因爲我手動鍵入風格=「顯示:無」,可能是此錯誤的一個原因。修改了下面的代碼。你能指出任何解決方案嗎?

driver.find_element(by='xpath', value="//table[@class='input table']//input[@id='gwt-debug-url-suggest-box']") 

driver.find_element(by='xpath', value="//input[@id='gwt-debug-url-suggest-box']")

driver.find_element_by_id("gwt-uid-47") 

driver.find_element(by='xpath', value="//div[contains(@class, 'sppb-b')][normalize-space()='www.example.com/page']") 

下面是HTML源代碼:

<div> 
    <div class="spH-c" id="gwt-uid-64"> Your landing page </div> 
    <div class="spH-f"> 
     <table class="input-table" width="100%"> 
      <tbody> 
       <tr> 
        <td class="spA-e"> 
         <div class="sppb-a" id="gwt-uid-47"> 
          <div class="sppb-b spA-b" aria-hidden="true" style="display: none;">www.example.com/page</div> 
          <input type="text" class="spC-a sppb-c" id="gwt-debug-url-suggest-box" aria-labelledby="gwt-uid-64 gwt-uid-47" dir=""> 
          </div> 
          <div class="error" style="display:none" id="gwt-debug-invalid-url-error-message" role="alert"> Please enter a valid URL. </div> 
         </td> 
         <td class="spB-b"> 
          <div class="spB-a" aria-hidden="true" style="display: none;"></div> 
         </td> 
        </tr> 
       </tbody> 
      </table> 
     </div> 
    </div> 
+0

當您在瀏覽器中關注/單擊元素時 - 您是否看到HTML相關部分發生變化?謝謝。 – alecxe

+0

是的,我只注意到HTML正在改變,因爲我手動鍵入類似

;請注意:顯示現在沒有。任何解決這個 –

+0

我已經更新了答案一點點。如果不能重現問題很難說清楚。我懷疑你點擊提示框後會出現一個不同的元素。嘗試手動檢查您在瀏覽器中輸入的元素 - 它與提示框相同嗎?希望有所幫助。 – alecxe

回答

0

有你在試圖選擇:

driver.find_element_by_id("gwt-debug-url-suggest-box") 
driver.send_keys("Your input") 

這樣,你直接選擇輸入。 無論如何,鏈接的網頁會有所幫助。