簡體   English   中英

從包含多個文本的表格單元格中提取單個文本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] / text())。 在表中,我有一些單元格,其中一個單元格中包含許多單獨的文本元素。 我正在嘗試從單元格中選擇一個特定的文本元素,並將其用作變量,但到目前為止失敗了。

作為一個例子,我嘗試了這個:

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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM