Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python/SeleniumWebDriver处理Angularjs/Javascript下拉列表?_Javascript_Python_Angularjs_Selenium_Xpath - Fatal编程技术网

如何使用Python/SeleniumWebDriver处理Angularjs/Javascript下拉列表?

如何使用Python/SeleniumWebDriver处理Angularjs/Javascript下拉列表?,javascript,python,angularjs,selenium,xpath,Javascript,Python,Angularjs,Selenium,Xpath,我想在Chromium浏览器上使用Python和Selenium webdriver自动化一些浏览器任务。我的python脚本已经能够登录、导航到子页面/进行一些单击,并在表单中插入一些内容 我的问题是一个强制性的下拉列表,在这里我必须选择一些东西才能继续。我认为该网页包含angularjs/javascript(下面代码的第三行)来创建下拉列表,我不知道如何处理 问题似乎是1)定位元素(xpath有时可能会更改),2)我无法单击或发送指向所找到内容的键。此外,我还尝试了一些“WebDriver

我想在Chromium浏览器上使用Python和Selenium webdriver自动化一些浏览器任务。我的python脚本已经能够登录、导航到子页面/进行一些单击,并在表单中插入一些内容

我的问题是一个强制性的下拉列表,在这里我必须选择一些东西才能继续。我认为该网页包含angularjs/javascript(下面代码的第三行)来创建下拉列表,我不知道如何处理

问题似乎是1)定位元素(xpath有时可能会更改),2)我无法单击或发送指向所找到内容的键。此外,我还尝试了一些“WebDriverWait”和sleep命令以及“wait.until(预期的\u条件。元素的可见性\u位于((By.XPATH,…))”…到目前为止运气不好

仅仅用Python和Selenium就可以解决这个问题吗? 或者我需要类似于量角器的东西(量角器是否只适用于Javascript命令)?我也看到了Pytractor

我是一个新手,有人能解释一下什么是解决这个问题的好方法吗?提前谢谢…)

网页代码如下所示(使用Firebug/Firepath抓取):


为了自动化任何用Angular JS开发的网页,我们必须使用开源工具“量角器”。Selenium本身不支持Angular JS web应用程序自动化。有关量角器的更多信息,请参阅下面的文章

量角器还使用与selenium相同的命令

希望这有帮助

<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>