簡體   English   中英

在計算表中的行時出現Robot Framework錯誤

[英]Robot Framework error in counting rows from table

我試圖將可以在頁面上顯示為10、20或50行的表中的表中的所有行數進行計數。 我在數據庫中有71條記錄,因此在頁面上,當我選擇每頁10行時,有8個表鏈接。 以下代碼可以正常工作,並返回到第6頁的行總和,該行表明合計值為60,但是在下一次迭代中,它無法計數第7頁的10條記錄,並且僅返回1,因此我得到的總數為61,而不是71.在此過程中似乎忽略了頁面。

在Hemanthvrm在下面發表評論后,我查看了html,發現此問題是由於頁面導航表上的范圍問題引起的。 此頁面導航表有10個框<Prev>|1|2|3|4|5|...|8|<Next>

xpath的范圍從// [@ id =“ study_paginate”] / ul / li [2] / a到// [@ id =“ study_paginate”] / ul / li [8] / a

但是,當單擊第5頁時,導航表將更改為

<Prev>|1|...|4|5|6|7|8|<Next>

但是相對位置的xpath保持不變,因此以前// // [@ id =“ study_paginate”] / ul / li [6] / a指的是第5頁,單擊第5頁后,// // [@ id =現在,“ study_paginate”] / ul / li [6] / a指向第6頁。由於系統已經單擊了該xpath(第5頁),因此在五次后它單擊了// * [@@ id =“ study_paginate”] / ul / li [7] / a,現在參考第7頁。 因此第6頁完全被省略了。

SAS_Temp_Tests
[Tags]    TEMP
Open Browser    http://localhost:5000/login/    Chrome
Maximize Browser Window
Wait Until Element Is Visible    id=submit
Input Text    id=email    ${User_Email}
Input Password    password    ${User_PW}
Click Element    id=submit
sleep    2s
Click Element    ${User_Menu Link}
Wait Until Element Is Visible    ${User_menu_Study_admin_Panel Link}
Click Element    ${User_menu_Study_admin_Panel Link}
sleep    3s
Comment    Click Element    xpath=//*[@id="study_length"]/label/select/option[4]
${rows}=    Get Matching Xpath Count    //*[@id="study"]/tbody/tr
Log    ${rows}
${Row_num}=    Evaluate    0
Set Global Variable    ${Row_num}
Log    ${Row_num}
: FOR    ${x}    IN RANGE    2    9999999
\    ${page}=    Run Keyword And Return Status    Element Should Be Visible    xpath=//*[@id="study_paginate"]/ul/li[${x}]/a
     ${y}    Evaluate    ${x}+1
\    ${No_Page}    Run Keyword And Return Status    Element Should Not Be Visible    xpath=//*[@id="study_paginate"]/ul/li[${y}]/a
\    Exit For Loop If    ${No_Page}
\    Click Element    xpath=//*[@id="study_paginate"]/ul/li[${x}]/a
\    Wait Until Element Is Visible    xpath=//*[@id="study"]
\    sleep    1s
\    ${rows}=    Get Matching Xpath Count    //*[@id="study"]/tbody/tr
\    ${Row_num}    Evaluate    ${Row_num}+${rows}
\    Log    ${Row_num}
Close All Browsers

通過此更新,有什么建議可以解決這個問題?

一切看起來不錯

*您測試過$ {x}中僅傳遞7嗎? 如果是,那么您有1或10嗎?
*您是否比較過7和6的表格格式?

暫無
暫無

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

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