繁体   English   中英

获取所有链接并遍历列表(机器人框架)

[英]get all links and iterate through list (robot framework)

我想检查某个收件箱中的所有物品,然后一个个地打开它们,直到没有更多为止(每个物品都会做一些处理,因此它们在被访问后便消失了)。 这些项目是基于工作流程的,因此当它们打开时,将对其进行处理并从收件箱中消失。

如何使机器人列出这些物品并逐一打开? 这是执行此任务的正确方法吗? 我在Eclipse W Python中使用robotframework

// span / a捕获收件箱中的所有相关链接(10) 在此处输入图片说明

我有以下代码可以获取所有链接并将它们放在列表中,但是我不知道最好的方法是一个一个地打开它们(每次打开链接并完成一些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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM