从包含多个文本Robot Framework的表格单元格中提取单个文本 [英] Extracting single Text from a table cell containing multiple texts Robot Framework
问题描述
我有一个表,其中一些单元格有多个文本,每个文本都有自己的xpath。例如,下面代码中的两个文本元素位于同一个表格单元格中,但有两个xpath:对于第一个B17AA038,xpath是// [@ id =profile_research] / tbody / tr [ 1] / td [10] / text()和下一个实例有另一个xpath(// [@ id =profile_research] / tbody / tr [1] / td [10] / div [2] /文本())。在表格中,我有一些单元格,其中包含许多单独的文本元素。我试图从单元格中选择一个特定的文本元素并将其用作变量,但到目前为止失败了。
I have a table in which some cells have multiple text and each text has its own xpath. An example, the two text elements in the code below are located in the same table cell, but has two xpaths : for the first "B17AA038" xpath is //[@id="profile_research"]/tbody/tr[1]/td[10]/text() and the next instance has another xpath (//[@id="profile_research"]/tbody/tr[1]/td[10]/div[2]/text()). In the table I have some cells that have many individual text elements packed in one cell. I am trying to select one particular text element from the cell and use it as variable , but so far failed.
作为一个例子,我试过这个:
as an example, I tried this:
Run keyword if '${Row_No}'=='1' get text xpath=//*[@id="profile_research"]/tbody/tr[${Table_Row}]/td[10]/text()
并收到以下错误消息:
InvalidSelectorException: Message: invalid selector: The result of the xpath expression "//*[@id="profile_research"]/tbody/tr[2]/td[10]/text()" is: [object Text]. It should be an element.
相关的html如下:
<td style="word-wrap: break-word; min-width: 120px; max-width: 120px; white-space:nowrap;">
<!-- sample level pandh_id-->
<!-- test level pandh_id-->
**B17AA03**8 <span class="badge badge-info" style="background-color: white; color:black; border:1px solid #808080; margin-bottom:2px; font-size:0.5em;">2</span>
<!-- hidden print div for add test to this sample-->
<div class="hidden-print" style="padding-bottom:1.275em; padding-right:3em;">
<a href="/research_add_test/CS16EB/IN428A/R17AA038?subject_uuid=sub3c968403c0f248a89442b99ccca91fb4&external_case_id=sfdgsfdg&external_subject_id=sfgdsfdg&subject_id=RS1001&page=1&study_id=pandh_ST_1&some_list=Proband&some_list=None" style="text-decoration:none" title="order another test to this sample">
<i class="fa fa-plus" aria-hidden="true" style="font-size:12px;"></i>
<i class="fa fa-file" aria-hidden="true"></i>
</a>
</div>
<!-- if it has more than 1-->
<!-- if sample pandh id and test pandh id matches-->
<!-- test level pandh_id-->
<div class="hidden-print" style="padding-bottom:2.575em; visibility:hidden;">
**B17AA038**
</div>
<!-- if it has more than 1-->
<!-- if sample pandh id and test pandh id matches-->
<!-- test level loop-->
<!-- sample level loop-->
</td>
任何建议都将不胜感激。谢谢
Any suggestion will be appreciated. Thanks
推荐答案
如错误所示,获取文本
关键字需要导致元素的定位器,而不是元素的文本。实质上,您要求selenium获取元素文本的文本。
As the error implies, the get text
keyword requires a locator that results in an element, not the text of an element. In essence, you are asking selenium to get the text of the text of an element.
解决方案是删除 text()来自定位器的code>:
xpath=//*[@id="profile_research"]/tbody/tr[${Table_Row}]/td[10]
这篇关于从包含多个文本Robot Framework的表格单元格中提取单个文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!