错误录制后纠正XPath

时间:2015-06-03 15:20:41

标签: selenium xpath

下午好,我是自动化测试的新手,非常感谢任何关于如何为控件找到正确的XPath的指导者,Selenium IDE或Selenium构建器似乎错误地识别了控件。

汽车类 - Selenium IDE录制的XPath ID相对:

//div[@id='content']/div/div/div/div/section/form/div/div/div/div/div/div[4]/div[2]/div/div/div[2]/ng-include/div/div/span
  • XPath职位:

    // NG-包括/ DIV / DIV /跨度

汽车和车辆租赁子类别 - Selenium IDE记录的XPath ID - XPath ID Relative:

//div[@id='content']/div/div/div/div/section/form/div/div/div/div/div/div[4]/div[2]/div/div/div[2]/ng-include/div[2]/div/ng-include/div/div/span
  • XPath职位:

    // DIV [2] / DIV / NG-包括/ DIV / DIV /跨度

源代码示例

  <label>Categories *</label>
                <div class="validation-message ng-hide" ng-show="createOfferForm.selectedCategoriesTree.$wasInvalidOnBlur || createOfferForm.selectedCategoriesTree.$invalidated">
                    Please select at least one category

                </div>
                <br/>
                <script type="text/ng-template" id="category-template.html">
                    <div class="list-group-item box-list-item" ng-class="{selected: category.Selected}" ng-click="toggleSelect(category, listCategories);">

                        <div>

                            <span class="box-title truncate category">{{category.Title}}</span>

                            <span class="box-icon" ng-init="category.expanded = false" ng-show="showChevron(category)">

                                <i class="fa fa-chevron-up" ng-click="category.expanded = !category.expanded; $event.stopPropagation();" ng-show="category.expanded"></i>

                                <i class="fa fa-chevron-down" ng-click="expand(category); category.expanded = !category.expanded; $event.stopPropagation();" ng-hide="category.expanded"></i>

                            </span>

                        </div>

                    </div>

                    <div ng-show="category.expanded">

                        <div class="sub-level" ng-repeat="category in category.listCategories">

                            <ng-include src="'category-template.html'"></ng-include>
                        </div>
                    </div>

                </script>
                <div class="pure-g">
                    <div class="pure-u-1">
                        <i>Available</i>
                        <div class="categories-list box-list" tabindex="5">
                            <span ng-if="!listCategories.length" ng-hide="overlaySelected"><strong>The domain has to be selected in order to see the list of categories!</strong></span>
                            <div class="loading" ng-show="overlaySelected">
                                <div class="spinner-wrapper">
                                    <span class="spinner-text">LOADING</span>
                                    <span class="spinner"></span>
                                </div>
                            </div>
                            <div class="level" ng-repeat="category in listCategories" ng-model="category">
                                <ng-include src="'category-template.html'"></ng-include>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="pure-g mtH1">
                    <div class="pure-u-1">
                        <i>Selected</i>
                        <div class="categories-selected unload">
                            <ul class="box-list" ng-cloak ng-model="selectedCategoriesTree" name="selectedCategoriesTree" not-empty ng-was-invalid-on-blur tabindex="6" ng-class="{invalid: createOfferForm.selectedCategoriesTree.$wasInvalidOnBlur || createOfferForm.selectedCategoriesTree.$invalidated}">
                                <li ng-repeat="categoriesRow in selectedCategoriesTree" ng-cloak class="list-group-item">
                                    <label class="box-list-item" ng-repeat="category in categoriesRow">
                                        <div>
                                            <span class="box-title">{{ category.Title }}</span>
                                            <span class="box-icon"><i class="fa fa-times" ng-click="removeSelected(category.Id)"></i></span>
                                        </div>
                                    </label>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:-1)

不完全确定您要映射的元素,无论哪种方式,您是否考虑过使用css进行映射?

例如,如果您尝试映射下面的范围:

<span ng-if="!listCategories.length" ng-hide="overlaySelected"><strong>The domain has to be selected in order to see the list of categories!</strong></span>

尝试使用以下css路径:

cssSelector = ".categories-list box-list > span"

快速提示 -

EDIT 为什么我相信你应该尽可能避免使用xpath:

css / xpath选择器之间的性能差异基本上是零,除非你在旧版本的IE中处理它。所以在选择一个时不要考虑到这一点......虽然,我选择CSS选择器的主要原因是可读性。这是你的开发者和ux家伙之间的共同语言......