Robotframework:Selenium2Lib:等到(...)关键字 [英] Robotframework: Selenium2Lib: Wait Until (...) Keywords

查看:200
本文介绍了Robotframework:Selenium2Lib:等到(...)关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium2 w RF测试相当复杂的Web应用程序的GUI.由于元素加载确实失败,因此想知道关键字之间的区别是什么:

I am using Selenium2 w RF to test GUI of rather complex web application. Since I do get some fails with elements load, would like to know what are differences between keywords:

等待直到启用元素 定位器 等待直到元素可见 定位器 等待页面包含元素 定位符

当我要检查页面的元素是否已完全加载并可以使用时,每个关键字的具体含义是什么?在使用哪种关键字时,哪个关键字最可靠? 是否有关键字可以检查是否已加载整页?

What is the scoope of each one and which keyword is most reliable in case, when I wanna check if element of the page is fully loaded and ready to use? Is there a keyword that checks if a full page is loaded?

推荐答案

我不知道您所说的范围"是什么意思.它们都在相同的范围内工作.

I don't know what you mean by "scope". They all work in the same scope.

Wait Until Element Is Enabled假定该元素存在于页面上,并且将等待直到启用该元素(非只读且未禁用).如果该元素不存在,它将立即失败(或在超时后,如果您有隐式等待)

Wait Until Element Is Enabled assumes that the element exists on the page, and will wait until the element is enabled (not readonly, and not disabled). If the element does not exist, it will fail immediately (or after a timeout if you have an implicit wait)

Wait Until Element is Visible假定该元素存在于页面上,并将等待直到该元素可见.如果该元素不存在,它将立即失败(或在超时后,如果您有隐式等待)

Wait Until Element is Visible assumes that the element exists on the page, and will wait until the element is visible. If the element does not exist, it will fail immediately (or after a timeout if you have an implicit wait)

Wait Until Page Contains Element不对该元素进行任何假设.它等待直到元素实际在页面上,无论它是可见,不可见,启用还是禁用.它不需要隐式等待,因为此关键字是显式等待.

Wait Until Page Contains Element makes no assumptions about the element. It waits until the element is actually on the page, regardless if it is visible, invisible, enabled, or disabled. It does not require an implicit wait, since this keyword is an explicit wait.

当我想检查页面元素是否已完全加载并准备使用时,哪个关键字最可靠?

which keyword is most reliable in case, when I wanna check if element of the page is fully loaded and ready to use?

最完整的解决方案是等待它出现在页面上,等待它可见,然后等待它被启用.

The most complete solution is to wait for it to be on the page, wait for it to be visible, and then wait for it to be enabled.

如果该元素始终位于页面上,则可以跳过第一个检查(即:如果没有可创建或删除该元素的JavaScript).

If the element will always be on the page, you can skip the first check (ie: if there's no javascript that can create or delete the element).

如果该元素将始终处于启用状态,则无需等待它变为启用状态(即:如果没有用于禁用或启用该元素的javascript)

If the element will always be enabled, you don't need to wait for it to become enabled (ie: if there's no javascript to disable or enable the element)

对于简单的静态页面,实际上只需要检查一个元素是否可见.即使这样做通常也不是必需的,因为硒不会在打开页面之前从打开页面返回.当页面是动态的时,问题就来了.也就是说,在加载html之后,当有javascript可以更改页面上的内容以及该页面是可见的还是启用的.

For simple static pages, you really only need to check that an element is visible. Even that isn't usually necessary since selenium doesn't return from opening a page until the page is loaded. The problem comes when the page is dynamic. That is, when there is javascript that can change what is on the page and whether it is visible or enabled, after the html has loaded.

是否有一个关键字可以检查是否已加载整页?

Is there a keyword that checks if a full page is loaded?

否,因为加载"在不同的应用程序中可能具有不同的含义.完成加载html后,浏览器会将变量document.readyState设置为"complete".您可以使用Wait for condition return window.document.readyState === 'complete'之类的内容在机器人中进行检查.同样,如果您在页面上运行了javascript,这可能是不够的,因为在加载初始HTML之后页面可能会更改.

No, because "is loaded" can mean different things in different applications. The browser will set the variable document.readyState to "complete" when it's done loading the html. You can check for that in robot with something like Wait for condition return window.document.readyState === 'complete'. Again, if you have javascript that runs on the page, this may not be sufficient since the page might change after the initial HTML is loaded.

没有一种适用于所有应用程序的解决方案.您需要了解应用在启动时的工作方式,并进行适当的检查.

There is no single solution that works for all apps. It's up to you to understand what the app is doing at startup, and to make the appropriate checks.

有关如何知道何时使用原始python和selenium完全加载页面的详细讨论,请参见博客文章

For a nice discussion of how to know when a page is fully loaded using raw python and selenium, see the blog post How to get Selenium to wait for page load after a click

这篇关于Robotframework:Selenium2Lib:等到(...)关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆