从包含多个文本机器人框架的表单元中提取单个文本



我有一个表,其中某些单元格具有多个文本,每个文本都有其自己的xpath。一个示例,下面代码中的两个文本元素位于同一表单元格中,但具有两个XPATH:对于第一个" B17AA038" XPATH是// [@ID =" profile_research"]/tbody/tr [1]/td [10]/text(),下一个实例有另一个xpath(// [@ID =" profile_research"]/文本())。在表中,我有一些单元格在一个单元格中包装许多单独的文本元素。我正在尝试从单元格中选择一个特定的文本元素并将其用作变量,但到目前为止失败了。

作为一个例子,我尝试了:

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&nbsp;<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&amp;external_case_id=sfdgsfdg&amp;external_subject_id=sfgdsfdg&amp;subject_id=RS1001&amp;page=1&amp;study_id=pandh_ST_1&amp;some_list=Proband&amp;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>

任何建议将不胜感激。谢谢

正如错误所暗示的那样, get text关键字需要一个定位器,该定位器会导致元素,而不是元素的文本。本质上,您要求硒获得元素文本的文字。

解决方案是从定位器中删除text()

xpath=//*[@id="profile_research"]/tbody/tr[${Table_Row}]/td[10]

最新更新