[英]get all links and iterate through list (robot framework)
我想檢查某個收件箱中的所有物品,然后一個個地打開它們,直到沒有更多為止(每個物品都會做一些處理,因此它們在被訪問后便消失了)。 這些項目是基於工作流程的,因此當它們打開時,將對其進行處理並從收件箱中消失。
如何使機器人列出這些物品並逐一打開? 這是執行此任務的正確方法嗎? 我在Eclipse W Python中使用robotframework
我有以下代碼可以獲取所有鏈接並將它們放在列表中,但是我不知道最好的方法是一個一個地打開它們(每次打開鏈接並完成一些X流程后都返回到收件箱) 。
Wait Until Element is Visible xpath=//a/span
# Count number of links on page
${AllLinksCount}= Get Matching Xpath Count xpath=//a/span
# Log the count of links
Log ${AllLinksCount}
# Create a list to store the link texts
@{LinkItems} Create List
# Loop through all links and store links value that has length more than 1 character
: FOR ${INDEX} IN RANGE 1 ${AllLinksCount}
\ Log ${INDEX}
\ ${lintext}= Get Text xpath=(//a/span)[${INDEX}]
\ Log ${lintext}
\ ${linklength} Get Length ${lintext}
\ Run Keyword If ${linklength}>1 Append To List ${LinkItems} ${lintext}
${LinkSize}= Get Length ${LinkItems}
Log ${LinkSize}
Comment Print all links
: FOR ${ELEMENT} IN @{LinkItems}
\ Log ${ELEMENT}
如果您想返回到原來的頁面,可以在單擊鏈接之前獲取位置,然后在處理后返回該URL。 您甚至不需要為此創建鏈接測試列表。 並為您的xpath使其//a/span[string-length(text())>1]
這樣您就不再需要run keyword if
了:
Wait Until Element is Visible
xpath=//a/span[string-length(text())>1]
${AllLinksCount}= Get Matching Xpath Count xpath=//a/span[string-length(text())>1]
Log ${AllLinksCount}
: FOR ${INDEX} IN RANGE 1 ${AllLinksCount}
\ Log ${INDEX}
\ ${currUrl} get location
\ click element xpath=(//a/span[string-length(text())>1])[1]
\ do processing here
\ go to ${currUrl}
如果URL更改,則只需通過以前的操作再次返回該頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.