Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A small change to apply retry when a pop up appears
public class ElementProxy implements InvocationHandler {
private final WebElement element;
public ElementProxy(WebElement element) {
this.element = element;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
for(int i = 0; i < 10 /*limit that can be set programatically*/ ; i++)
{
try
{
//before invoking actual method check for the popup
this.checkForPopupAndKill();
//at this point, popup would have been closed if it had appeared. element action can be called safely now.
return method.invoke(element, args);
}
catch(exception exp)
{
// Just remain in the loop
}
}
}
private void checkForPopupAndKill() {
if (popup.isDisplayed()) {
System.out.println("You damn popup, you appearded again!!?? I am gonna kill you now!!");
popup.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment