如何使用Python/Selenium网络驱动程序处理Angularjs/Javascript下拉列表
How to handle Angularjs / Javascript dropdown using Python / Selenium webdriver?
我想在Chromium浏览器上使用Python和Selenium网络驱动程序来自动化一些浏览器任务。我的python脚本已经能够登录,导航到一个子页面/进行一些点击,并在表单中插入一些内容
我的问题是一个强制性的下拉列表,在那里我必须选择一些东西才能继续。我认为网页在这一点上(下面代码的第三行)包含angularjs/javascript来创建下拉列表,我不知道如何处理。
问题似乎是1)定位元素(xpath有时似乎会更改),2)我无法点击或发送我找到的内容的键。此外,我还尝试了一些"WebDriverWait"和sleep命令以及"wait.till(expectedconditions.visibility_of_element_located((By.XPATH,…))"……到目前为止运气不佳。
仅仅用Python和Selenium就有可能解决这个问题吗?或者我需要像Protractor这样的东西吗(Protractor只是使用Javascript命令吗)?我也见过Pytrator。。。
关于这件事,我是个新手,有人能解释一下解决这个问题的好方法吗?提前感谢…:)
网页代码如下(使用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>
为了自动化在Angular JS中开发的任何网页,我们必须使用开源工具"Protractor"。Selenium本身不会支持Angular JS web应用程序的自动化。有关Protractor的更多信息,请参阅以下文章
使用Protractor 测试Angular JS应用程序
量角器也使用与selenium相同的命令。
希望这能有所帮助。
- 如何使用angularjs处理多页网站
- 使用angularJs处理实时数据
- 使用AngularJS处理嵌套ng重复.无法通过ng单击来获取按钮
- 无法让AngularJS处理JSFiddle
- 如何使用 AngularJS 处理文档单击并通知其他控制器
- AngularJS - 处理错误错误:[ng:areq] 在此特殊情况下 (?)
- AngularJS - 处理重复的片段,如页眉和页脚
- 使用套接字io和angularjs处理频繁变化的时间序列数据的策略
- 使用 angularjs 处理由三部分组成的日期字段验证
- Angularjs处理承诺和模型
- 通过 AngularJS 处理 Firefox 中的数字输入
- 如何使用AngularJS处理数据的递归呈现
- 为什么不是't AngularJS处理页面加载后附加到页面的元素
- AngularJS-处理手动输入URL状态的最佳方式
- AngularJS:处理回调和承诺
- AngularJS处理格式化的数字输入
- Angularjs处理$resource $promise错误
- 使用AngularJS处理自定义的localStorage数据
- 使用AngularJS'处理64位数字;美元http.get()
- AngularJS:处理具有相同输入名称的值