Skip to content

Instantly share code, notes, and snippets.

@virenv
Created July 28, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virenv/6a24b4fb882e47540d148c4581e6e5ea to your computer and use it in GitHub Desktop.
Save virenv/6a24b4fb882e47540d148c4581e6e5ea to your computer and use it in GitHub Desktop.
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