我需要从下面的span标记中获取文本'Finance',以便将其与保存在文件中的其他值进行比较。但我无法获取它。
<span class="panel-text col-md-8">Finance</span>
以下是
的完整代码<efx-dashboard-panel> <div class="dashboard-panel dashboard-type-employee-input">
<div class="dashboard-panel-header">
<i class="fa fa-edit"></i>
<span class="dashboard-panel-title">Provided Employee Input</span>
</div>
<div class="dashboard-panel-content">
<!----><div class="ng-star-inserted">
<!---->
<!----><div class="col-md-12 ng-star-inserted">
<span class="panel-text label col-md-4">Department in which the employee works:</span><span class="panel-text col-md-8">Finance</span>
</div>
</div><div class="ng-star-inserted">
<!---->
<!----><div class="col-md-12 ng-star-inserted">
<span class="panel-text label col-md-4">Employee's Date of Birth:</span><span class="panel-text col-md-8">03-08-1990</span>
</div>
</div><div class="ng-star-inserted">
<!---->
<!----><div class="col-md-12 ng-star-inserted">
<span class="panel-text label col-md-4">County in which the employee works:</span><span class="panel-text col-md-8">Iowa</span>
</div>
</div><div class="ng-star-inserted">
<!---->
<!----><div class="col-md-12 ng-star-inserted">
<span class="panel-text label col-md-4">Employee's home address:</span><span class="panel-text col-md-8">Station Street</span>
</div>
</div><div class="ng-star-inserted">
<!---->
<!----><div class="col-md-12 ng-star-inserted">
<span class="panel-text label col-md-4">Employee ID:</span><span class="panel-text col-md-8">M1669</span>
</div>
</div><div class="ng-star-inserted">
<!---->
<!----><div class="col-md-12 ng-star-inserted">
<span class="panel-text label col-md-4">Authorization Code:</span><span class="panel-text col-md-8">45637</span>
</div>
</div>
</div>
</div></efx-dashboard-panel>
以上代码的xpath选择器如下所示
element(by.xpath('//*[@id="employer-call"]/div[2]/div[2]/efx-tabs/div/efx-tab[4]/div/div/employee-input-panel/efx-dashboard-panel/div/div[2]/div[1]/div/span[2]'));
如何从tag中获取文本。我尝试使用text(),getText()和innerHTML。
答案 0 :(得分:0)
这个XPath,
//span[normalize-space()="Department in which the employee works:"]
/following-sibling::span[1]
将紧随span
后面的span
兄弟,其空格规范化字符串值为"Department in which the employee works:"
。
您可以附加/text()
以仅选择上述span
的文本节点,或将整个XPath表达式包装在string()
中以获取其字符串值。
答案 1 :(得分:0)
我通过参考
得到了解决方案我使用了expect(this.deptData.getText()).to.eventually.equal(employee.department);
从span标记中获取数据并将其与employee.department中的数据进行比较