我要使用Robotframework提取此html代码中包含的列表的每个元素的文本:
<li class="ui-select-choices-group" id="ui-select-choices-6">
<div class="divider ng-hide" ng-show="$select.isGrouped && $index > 0"></div>
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label dropdown-header ng-binding ng-hide" ng-bind="$group.name"></div>
<!-- ngRepeat: tenant in $select.items -->
<!-- ngIf: $select.open -->
<div ng-attr-id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row ng-scope active" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option" ng-repeat="tenant in $select.items" ng-if="$select.open" ng-click="$select.select(tenant,$select.skipFocusser,$event)" id="ui-select-choices-row-6-0" style="">
<span class="ui-select-choices-row-inner" uis-transclude-append="">
<div ng-bind-html="tenant.name | highlight: $select.search" class="ng-binding ng-scope">RF_Account-1-</div>
</span>
</div>
<!-- end ngIf: $select.open -->
<!-- end ngRepeat: tenant in $select.items -->
<!-- ngIf: $select.open -->
<div ng-attr-id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row ng-scope" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option" ng-repeat="tenant in $select.items" ng-if="$select.open" ng-click="$select.select(tenant,$select.skipFocusser,$event)" id="ui-select-choices-row-6-1" style="">
<span class="ui-select-choices-row-inner" uis-transclude-append="">
<div ng-bind-html="tenant.name | highlight: $select.search" class="ng-binding ng-scope">RF_Account-2-</div>
</span>
</div>
<!-- end ngIf: $select.open -->
<!-- end ngRepeat: tenant in $select.items -->
<!-- ngIf: $select.open -->
<div ng-attr-id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row ng-scope" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option" ng-repeat="tenant in $select.items" ng-if="$select.open" ng-click="$select.select(tenant,$select.skipFocusser,$event)" id="ui-select-choices-row-6-2">
<span class="ui-select-choices-row-inner" uis-transclude-append="">
<div ng-bind-html="tenant.name | highlight: $select.search" class="ng-binding ng-scope">RF_Account-3-</div>
</span>
</div>
<!-- end ngIf: $select.open -->
<!-- end ngRepeat: tenant in $select.items -->
<!-- ngIf: $select.open -->
<div ng-attr-id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row ng-scope" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option" ng-repeat="tenant in $select.items" ng-if="$select.open" ng-click="$select.select(tenant,$select.skipFocusser,$event)" id="ui-select-choices-row-6-3">
<span class="ui-select-choices-row-inner" uis-transclude-append="">
<div ng-bind-html="tenant.name | highlight: $select.search" class="ng-binding ng-scope">RF_Account-4-</div>
</span>
</div>
<!-- end ngIf: $select.open -->
<!-- end ngRepeat: tenant in $select.items -->
<!-- ngIf: $select.open -->
<div ng-attr-id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row ng-scope" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option" ng-repeat="tenant in $select.items" ng-if="$select.open" ng-click="$select.select(tenant,$select.skipFocusser,$event)" id="ui-select-choices-row-6-4">
<span class="ui-select-choices-row-inner" uis-transclude-append="">
<div ng-bind-html="tenant.name | highlight: $select.search" class="ng-binding ng-scope">RF_Account-5-</div>
</span>
</div>
<!-- end ngIf: $select.open -->
<!-- end ngRepeat: tenant in $select.items -->
<!-- ngIf: $select.open -->
<div ng-attr-id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row ng-scope" ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option" ng-repeat="tenant in $select.items" ng-if="$select.open" ng-click="$select.select(tenant,$select.skipFocusser,$event)" id="ui-select-choices-row-6-5">
<span class="ui-select-choices-row-inner" uis-transclude-append="">
<div ng-bind-html="tenant.name | highlight: $select.search" class="ng-binding ng-scope">RF_Account-6-</div>
</span>
</div>
<!-- end ngIf: $select.open -->
<!-- end ngRepeat: tenant in $select.items -->
</li>
我在Robotframework中的实际代码是:
${maxTenant} Get Element Count //li[@class='ui-select-choices-group']//span
${accounts} Create Dictionary
:FOR ${i} IN RANGE 0 ${maxTenant}
\ ${elementId} Get Element Attribute //li[@class='ui-select-choices-group']//div[3+${i}] id
\ ${elementName} Get Text ${elementId}
\ Set To Dictionary ${accounts} ${elementName}
Log Dictionary ${accounts}
执行脚本时,$ {accounts}词典始终为空。 您能帮我理解我的错误吗?
答案 0 :(得分:0)
使用此代码,它可以工作
${maxTenant} Get Element Count //li[@class='ui-select-choices-group']//span
${tenants} Create List
:FOR ${i} IN RANGE 0 ${maxTenant}
\ ${elementName} Get Text //li[@class='ui-select-choices-group']//div[3+${i}]/*
\ Append To List ${tenants} ${elementName}
Log List ${tenants}
我不明白为什么。有人可以帮我理解吗?