简体   繁体   English

Robot Framework 如果元素可见,则执行关键字

[英]Robot Framework If element is visible execute a keyword

I have a page that may and may not contain a certain element that will affect all the xpaths.我有一个页面可能包含也可能不包含会影响所有 xpath 的某个元素。

I need to run a "Run Keyword If" to identify if this element exists and if so to execute another keyword.我需要运行一个“Run Keyword If”来确定这个元素是否存在,如果存在则执行另一个关键字。

I tried to set the "Page Should Contain Element" and "Element Should Be Visible" as variables and pass it in the If statement but it only return None.我试图将“页面应该包含元素”和“元素应该可见”设置为变量并将其传递到 If 语句中,但它只返回 None。

What can I use to identify an element in a page?我可以用什么来标识页面中的元素?

I experienced the same issue, I use this solution:我遇到了同样的问题,我使用了这个解决方案:

${present}=  Run Keyword And Return Status    Element Should Be Visible   id=my-element
Run Keyword If    ${present}    My Cool Keyword

I had similar situation and I used the script below:我有类似的情况,我使用了下面的脚本:

${IsElementVisible}=  Run Keyword And Return Status    Element Should Be Visible   ${Element1}
Run Keyword If    ${IsElementVisible}  MyCase1  ELSE  Click Element  ${Element2}

Here's a faster and less wordy alternative:这是一个更快、更简洁的替代方案:

${c} =   Get Element Count   ${locator}
Run Keyword If   ${c}>0    Call Your Keyword Here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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