除了leanft.exists()和下面的内容之外,还有其他的等待吗?我回来要等很久才能确定有什么东西是可点击的
我的应用程序是一个使用ReactJS的单一页面Javascript应用程序。挑战是,有时selenium单击不起作用。它执行行,但没有导航到下一个路由或页面。此外,在执行期望在新页上的下一行之前,它不会引发异常。我将不得不再次执行单击。本质上,我需要一种将条件传递给click方法的方法,以验证如果单击某个元素,我希望看到其他元素。如果单击没有发生,则返回false并再次单击。这有意义吗?
发布于 2018-03-26 05:00:56
我看到您链接到C# sdk,所以我将在C#中回答。
WaitUntil执行提供的布尔方法,直到它返回true为止。因此,如果您实现了自己的方法:
private bool funcToRun(IBrowser arg)
{
// imeplement whatever logic you want here
return true;
}然后您可以按如下方式调用WaitUntil:browser.WaitUntil(funcToRun);
当然,确保funcToRun使用正确的测试对象(实际上调用.WaitUntil的测试对象)作为参数。
由于您可以访问funcToRun方法中的测试对象,所以可以等待到您想要的任何逻辑。下面是使用箭头函数的另一个例子,它不等待按钮到.Exist(),而是等待Buttons数组具有16元素。
// Create a description for the Toolbar.
var toolBar = window.Describe<IToolBar>(new ToolBarDescription
{
NativeClass = "SwingSet2$ToggleButtonToolBar"
});
// There are 16 buttons in the toolbar. Use the WaitUntil method to wait until all 16 buttons are loaded.
// This ensures that any button we press was loaded. If not loaded, the test fails.
toolBar.WaitUntil(tb => (tb.Buttons.Count == 16));https://stackoverflow.com/questions/49482060
复制相似问题