簡體   English   中英

python Selenium send_keys到Jupyter筆記本

[英]python Selenium send_keys to a Jupyter notebook

我正在嘗試使用python中的硒自動輸入到Jupyter筆記本。

我正在嘗試對DOM中的各種元素使用send_keys()方法,到目前為止,我嘗試過的所有操作都有以下問題:

selenium.common.exceptions.ElementNotInteractableException: Message: Element <span> is not reachable by keyboard

到目前為止,我已經嘗試過返回以下要素的定位器:

  • (“標簽名稱”,“文本區域”)[但是,這是隱藏的,因此不可交互]
  • ('class','CodeMirror-code')元素下的('tag name','pre')
  • ('class','CodeMirror-code')元素下的('tag name','span')
  • (“標簽名稱”,“ span”)

可以看到DOM中沒有明顯的input 有沒有人嘗試自動化Jupyter筆記本?

似乎在屏幕上手動鍵入文本區域時,DOM正在動態更改下面的span元素...

這是我正在使用的DOM的相關部分以及textarea的屏幕截圖 輸入

<div class="cell code_cell rendered selected" tabindex="2">
   <div class="input">
      <div class="run_this_cell" title="Run this cell"><i class="fa-step-forward fa"></i></div>
      <div class="prompt input_prompt"><bdi>In</bdi>&nbsp;[&nbsp;]:</div>
      <div class="inner_cell">
         <div class="ctb_hideshow">
            <div class="celltoolbar"></div>
         </div>
         <div class="input_area">
            <div class="CodeMirror cm-s-ipython">
               <div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 5.59375px; left: 5.59375px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div>
               <div class="CodeMirror-vscrollbar" cm-not-content="true">
                  <div style="min-width: 1px; height: 0px;"></div>
               </div>
               <div class="CodeMirror-hscrollbar" cm-not-content="true">
                  <div style="height: 100%; min-height: 1px; width: 0px;"></div>
               </div>
               <div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div>
               <div class="CodeMirror-gutter-filler" cm-not-content="true"></div>
               <div class="CodeMirror-scroll" tabindex="-1">
                  <div class="CodeMirror-sizer" style="margin-left: 0px; min-width: 8.59375px; margin-bottom: -15px; border-right-width: 15px; min-height: 28px; padding-right: 0px; padding-bottom: 0px;">
                     <div style="position: relative; top: 0px;">
                        <div class="CodeMirror-lines" role="presentation">
                           <div role="presentation" style="position: relative; outline: none;">
                              <div class="CodeMirror-measure"></div>
                              <div class="CodeMirror-measure"></div>
                              <div style="position: relative; z-index: 1;"></div>
                              <div class="CodeMirror-cursors" style="visibility: hidden;">
                                 <div class="CodeMirror-cursor" style="left: 5.59375px; top: 0px; height: 17px;">&nbsp;</div>
                              </div>
                              <div class="CodeMirror-code" role="presentation">
                                 <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div style="position: absolute; height: 15px; width: 1px; border-bottom: 0px solid transparent; top: 28px;"></div>
                  <div class="CodeMirror-gutters" style="display: none; height: 43px;"></div>
               </div>
            </div>
         </div>
      </div>
   </div>
   <div class="output_wrapper">
      <div class="out_prompt_overlay prompt" title="click to expand output; double click to hide output"></div>
      <div class="output"></div>
      <div class="btn btn-default output_collapsed" title="click to expand output" style="display: none;">. . .</div>
   </div>
</div>

注意:通過使textarea可見,然后向其發送密鑰,可以在通過JavaScript執行更改DOM時取得成功。 (這是通過從其繼承的父div元素的style屬性中刪除hidden;來完成的。但是,我正在尋找一種無需更改DOM的解決方案。

我認為問題是您試圖在不是文本輸入或textarea的元素上使用sendKeys()。

在單擊目標元素后,嘗試使用操作:

Actions builder = new Actions(driver);
builder.SendKeys("My input").Perform();

我在jsfiddle.net(也不使用標准textarea)上進行了測試,並完成了工作。

我的示例在c#中,有關執行操作鏈接的Python文檔可在此處找到。

我希望這有幫助。

暫無
暫無

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

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