2016-05-03 30 views
4

ChromiumブラウザでPythonとSelenium webdriverを使っていくつかのブラウザタスクを自動化したいと思っています。私のpythonスクリプトはすでにログインしたり、サブページに移動したり、いくつかのクリックをしたり、フォームに何かを挿入することができます。Python/Selenium webdriverを使ってAngularjs/Javascriptドロップダウンを扱うには?

私の問題は、私が続ける前に何かを選択しなければならない必須のドロップダウンリストです。私は、ウェブページにドロップダウンを作成するためにそのポイント(下のコードの3行目)にangularjs/javascriptが含まれていると思うし、それをどう扱うかわからない。

問題は1)要素の位置を特定する(xpathが時々変わるようです)、2)私が見つけたものをクリックしたりキーを送信できないようです。また、私はいくつかの種類の "WebDriverWait"とsleepコマンドと "wait.until(expected_conditions.visibility_of_element_located(By.XPATH、...))"を試しました...

PythonとSeleniumだけでその問題を解決することは可能でしょうか? または、分度器のようなものが必要ですか(また、分度器はJavascriptコマンドで動作しますか)?この問題を解決するにはどうすればいいのか説明してもらえますか?ありがとうございます。:)

ウェブページコードは次のようになります(Firebug/Firepathを使用して取得):

<div class="ng-scope ng-isolate-scope" model-contains-key="true" ref="salutations" cat-input-select="editDetail.salutation"> 
    <div id="s2id_autogen1" class="select2-container form-control ng-untouched ng-valid ng-dirty ng-valid-parse"> 
     <a class="select2-choice select2-default" tabindex="-1" href="javascript:void(0)"> 
      <span id="select2-chosen-2" class="select2-chosen"/> 
      <abbr class="select2-search-choice-close"/> 
      <span class="select2-arrow" role="presentation"> 
       <b role="presentation"/> 
      </span> 
     </a> 
     <label class="select2-offscreen" for="s2id_autogen2"/> 
     <input id="s2id_autogen2" class="select2-focusser select2-offscreen" type="text" role="button" aria-haspopup="true" aria-labelledby="select2-chosen-2"/> 
     <div class="select2-drop select2-display-none select2-with-searchbox"> 
      <div class="select2-search"> 
       <label class="select2-offscreen" for="s2id_autogen2_search"/> 
       <input id="s2id_autogen2_search" class="select2-input" type="text" aria-autocomplete="list" aria-expanded="true" role="combobox" spellcheck="false" autocapitalize="off" autocorrect="off" autocomplete="off" aria-owns="select2-results-2" placeholder=""/> 
      </div> 
      <ul id="select2-results-2" class="select2-results" role="listbox"/> 
     </div> 
    </div> 
    <select class="form-control ng-untouched ng-valid ng-dirty ng-valid-parse" ng-change="modelChanged(); changeCallback({value: selectValue.value})" ng-readonly="readonly" ng-disabled="disabled" ng-model="selectValue.value" ui-select2="{dropdownAutoWidth: 'true', allowClear: 'false'}" tabindex="-1" title="" style="display: none;"> 
     <option value=""/> 
     <!-- ngRepeat: option in options --> 
     <option class="ng-binding ng-scope ng-isolate-scope" cat-i18n="xxxxxxx.salutation.Mr" value="Mr" ng-repeat="option in options">Mr</option> 
     <!-- end ngRepeat: option in options --> 
     <option class="ng-binding ng-scope ng-isolate-scope" cat-i18n="xxxxxxx.salutation.Ms" value="Ms" ng-repeat="option in options">Ms</option> 
     <!-- end ngRepeat: option in options --> 
    </select> 
    <!-- ngIf: infoText --> 
</div> 

答えて

0

Angular JSで開発されたウェブページを自動化するには、オープンソースツール「分度器」を使用する必要があります。 Selenium自体はAngular JS Webアプリケーションの自動化をサポートしません。分度器の詳細については、以下の記事

Testing Angular JS application using Protractor

分度器もセレンが使用するのと同じコマンドを使用して参照してください。

これが役に立ちます。

関連する問題