1)场景:
界面A:登录界面(或其他界面),操作后,弹出一个新tab页或新窗口界面
界面B(弹出一个新tab页或新窗口界面):不能被RF操作,如click,input等
2)原因:
界面的句柄仍然聚焦在界面A上,所以RF无法识别界面B。也就是无法识别界面B的元素,也就导致无法通过Xpath进行定位和界面操作
3)解决:
方法1:通过handle句柄完成
#假设此次有RF代码,且界面A操作完了
#接下来代码,是为了操作界面B
${handle_list} Get Window Handles
Select Window ${handle_list}[1] #list从0开始即list[0],此次获取list[1] = 新tab窗口
Select Frame //*[@id="frame_top"] #新tab窗口,需要锁定frame。因为此时整个source page有多套html层级,需要锁定frame,再进行操作如click,input
click element //*[@id="trade"]
方法2:通过 Select Window NEW完成
#假设此次有RF代码,且界面A操作完了
#接下来代码,是为了操作界面B
Select Window NEW
Select Frame //*[@id="frame_top"]
click element //*[@id="trade"]
Select Window 备注:
By default, the locator is matched against window handle, name, title, and URL. Matching is done in that order and the first matching window is selected.
The locator can specify an explicit strategy by using the format strategy:value (recommended) or strategy=value. Supported strategies are name, title, and url. These matches windows using their name, title, or URL, respectively. Additionally, default can be used to explicitly use the default strategy explained above.
If the locator is NEW (case-insensitive), the latest opened window is selected. It is an error if this is the same as the current window.
If the locator is MAIN (default, case-insensitive), the main window is selected.
If the locator is CURRENT (case-insensitive), nothing is done. This effectively just returns the current window handle.
If the locator is not a string, it is expected to be a list of window handles to exclude. Such a list of excluded windows can be got from Get Window Handles before doing an action that opens a new window.