|
4 | 4 | import java.util.Optional; |
5 | 5 | import java.util.function.Supplier; |
6 | 6 |
|
| 7 | +import org.openqa.selenium.NoSuchElementException; |
| 8 | +import org.openqa.selenium.StaleElementReferenceException; |
7 | 9 | import org.openqa.selenium.WebElement; |
8 | 10 |
|
9 | 11 | import lombok.extern.slf4j.Slf4j; |
@@ -51,20 +53,38 @@ public Object invoke(Object proxy, Method method, Object[] args, Implementation |
51 | 53 | PageFragmentEventBuilder eventBuilder = getEventBuilderFor(producesEvent); |
52 | 54 | eventBuilder.setPageFragment(( PageFragment ) proxy); |
53 | 55 | if (eventBuilder.needsBeforeData()) { |
54 | | - eventBuilder.setBeforeData(webElementSupplier.get()); |
| 56 | + tryToSetBeforeData(eventBuilder); |
55 | 57 | } |
56 | 58 |
|
57 | 59 | Object returnObject = implementation.invoke(proxy, method, args); |
58 | 60 |
|
59 | 61 | if (eventBuilder.needsAfterData()) { |
60 | | - eventBuilder.setAfterData(webElementSupplier.get()); |
| 62 | + tryToSetAfterData(eventBuilder); |
61 | 63 | } |
62 | 64 |
|
63 | 65 | eventSystem.fireEvent(eventBuilder.build()); |
64 | 66 | return returnObject; |
65 | 67 |
|
66 | 68 | } |
67 | 69 |
|
| 70 | + private void tryToSetBeforeData(PageFragmentEventBuilder eventBuilder) { |
| 71 | + try { |
| 72 | + eventBuilder.setBeforeData(webElementSupplier.get()); |
| 73 | + } catch (NoSuchElementException | StaleElementReferenceException e) { |
| 74 | + log.warn("Exception while setting event before data: " + e.getMessage()); |
| 75 | + log.debug("Stacktrace for previous warning: ", e); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + private void tryToSetAfterData(PageFragmentEventBuilder eventBuilder) { |
| 80 | + try { |
| 81 | + eventBuilder.setAfterData(webElementSupplier.get()); |
| 82 | + } catch (NoSuchElementException | StaleElementReferenceException e) { |
| 83 | + log.warn("Exception while setting event after data: " + e.getMessage()); |
| 84 | + log.debug("Stacktrace for previous warning: ", e); |
| 85 | + } |
| 86 | + } |
| 87 | + |
68 | 88 | @SuppressWarnings("unchecked") |
69 | 89 | private PageFragmentEventBuilder getEventBuilderFor(Produces producesEvent) |
70 | 90 | throws IllegalAccessException, InstantiationException { |
|
0 commit comments