Splinterの使用中に発生した問題の概要


解決済み


1、selenium.common.exceptions.ElementNotVisibleException: Message: element not visible 2、selenium.common.exceptions.InvalidElementStateException:Message:invalid element state:Element is not currently interactable and may not be manipulated以上の2つの異常が発生する原理:1、要素がまだロードされていないうちに操作し、通常はalertボックスで、解決方法time.sleep(1)、時間は自分でデバッグします.2、要素は見えますが、コードを操作する要素はマウスに従ってスタイルを変更したり、他の条件をリアルタイムで変更したりして、コードが「見えない」ことができません.この場合、jsでdom要素を操作することでシーンに適応する必要があります.私はページをテストしてinputがあって、マウスが操作しない時にスタイルは以下の通りです:
<input id="batch_quto" value="0" data-role="numerictextbox" role="spinbutton" style="display: none;" class="k-input" type="text" aria-valuemin="0" aria-valuenow="0" aria-disabled="false" aria-readonly="false">

マウスで入力ボックスをクリックすると、スタイルは次のようになります.
<input id="batch_quto" value="0" data-role="numerictextbox" role="spinbutton" style="display: inline-block;" class="k-input" type="text" aria-valuemin="0" aria-valuenow="0" aria-disabled="false" aria-readonly="false">

両者の違い:
style="display: none;"
style="display: inline-block;"

displayプロパティ設定要素がどのように表示されるか.したがって、xpath、idによって要素を位置決めしてもinputにコードでテキストを入力することはできません.解決策は、splinterのjs実行方法を使用してinputのstyleプロパティを操作し、操作するいくつかのdivネストで操作する要素を発見することが本当の難点です.
#  4 3 
browser.evaluate_script('document.getElementById("batch_quto").style="display: inline-block; visibility: visible;"')
browser.evaluate_script('document.getElementById("batch_quto").contentEditable = true')
browser.find_by_id('batch_quto').fill("120")
#  
browser.evaluate_script('document.getElementById("batch_quto").style="display: none; visibility: visible;"')

3、Message: unknown error: Element ... is not clickable at point... 要素が見つかることを確認するとtime.sleep(1). 注意深くクリックする要素がブラウザの下部にあることに気づいたら、本当に何かの要素に遮られています.次のことができます.
# js 
browser.evaluate_script('window.scrollTo(0,800)')
# jquery , jquery , 
browser.evaluate_script('$(".mk-product-body").scrollTop(500)')
#  
browser.evaluate_script('$("input[id^=\'logisticsWeight\']").first().val("500")')
browser.evaluate_script('$("input[class=\'k-formatted-value noEdit k-input\']").first().click()')
browser.evaluate_script('$("input[id^=\'logisticsWeight\'").last().val("1500")')
browser.evaluate_script('$("input[class=\'k-formatted-value noEdit k-input\']").last().click()')

操作が速すぎて、手動で待たなければなりません.splinter定義のメソッドを変更したいのですが、読み取り専用です.の解決の構想はとても簡単で、githubの上でcloneの1部のsplinterのソースコード、ソースコードclick事件を修正して、1つのsleepをプラスして、更にソースコードを通じてsplinterをインストールすればいいです.