I have a Selenium Grid test and WebDriver 2.48.2 that runs too fast. Most of the time the test stops because the switch is not selected until the button is pressed.
Radio notes are configured using JavaScript based on the JSON file to create any number of them in the on-the-fly section. After clicking the Continue button, this section will be destroyed, and a new one will be created using the new switches.
I tried implicit waiting without success.
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
The only solution that works for me is a delay that allows enough time for the switch to click.
driver.findElement(By.id("radiobuttonid")).click();
Thread.sleep(delay);
But, in my opinion, this is not an ideal solution, perhaps the delay may be insufficient or too long, wasting time; there can be any number of switches so that the time increases exponentially.
I tried setting various explicit expectations with different expected conditions , but without success.
I tried to wait for the creation of the radio button, as it may not exist ( presenceOfElementLocated
and elementToBeClickable
). I tried to wait for his choice ( elementToBeSelected
).
I had trouble finding what the expected conditions should do, as the descriptions are short and open to misinterpretation.
Ideally, I want the test to continue shortly after pressing the switch. If possible, what is the best way to do this?
EDIT
L.Bar , , , , .
2
. , .
private static Predicate<WebDriver> forceSelectionOfElement (final String id)
{
return new Predicate<WebDriver>()
{
@Override
public boolean apply(WebDriver arg0)
{
WebElement element = arg0.findElement(By.id(id));
boolean rval = element.isSelected();
if (!rval) {
element.click();
}
return rval;
}
};
}
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(forceSelectionOfElement("q___01_02_01___1___a"));
, , , :)
import com.google.common.base.Predicate;