Are there other waits besides leanft.exists() and the following below. I'm back g to wait a lot to determine if something is clickable
My application is a Single Page Javascript application using ReactJS. The challenge is that sometimes the selenium click does not work. It executes the line, but I was not navigated to the next route or page. In addition, it does not throw an exception until you execute the next line expecting to be on the new page. I would have to perform the click again. In essence, I need a way to pass a condition to a click method to verify that if I click on some element I expect to see some other element. If the click does not happen return false and click again. Does that make sense?
I see you linked towards C# sdk, so I'll answer in C#.
WaitUntil
executes the provided boolean method until it returns true
. So if you implement your own method:
private bool funcToRun(IBrowser arg)
{
// imeplement whatever logic you want here
return true;
}
Then you can call WaitUntil
as follows: browser.WaitUntil(funcToRun);
Of course make sure that your funcToRun
takes as argument the correct test object (the one on which you'll actually call .WaitUntil
).
As you'll have access to the test object in the funcToRun
method, you can wait until any logic you want.
Here's another example using arrow functions, that doesn't wait for a button to .Exist()
, but for the Buttons
array to have 16
elements.:
// 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));