从包含多个文本Robot Framework的表格单元格中提取单个文本

时间:2017-08-28 23:17:22

标签: jquery python python-2.7 xpath robotframework

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

作为一个例子,我试过这个:

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>

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

1 个答案:

答案 0 :(得分:4)

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

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

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