I have created one override method(click()
method) in BaseElement class which implements from WebElement interface.
I would like to call this overridden method on all web elements wherever applicable.
WebElement ele = driver.findElement(By.id("button"));
// it returns webelement type by default
How Can I call my override click()
method on above web element?
I have tried with down casting ele to BaseElement like below:
BaseElement m_ele = (BaseElement) ele;
// No compilation error but throws runtime class casting exception
Any idea could help me here in order to call overridden click()
method on WebElement? I dont want to user in-built click()
method of WebElement.
Let me know if I have to provide any additional information?
Here is my code snippet:
public class BaseElement implements WebElement {
public BaseElement(WebElement element) {
m_element = element;
}
@Override
public void click() {
try {
m_element.click();
} catch (WebDriverException e) {
try {
logger.debug("Click Failed, Attempting to click by scrolling into view with bottom align option");
scrollIntoView();
m_element.click();
} catch (WebDriverException ef) {
try {
logger.debug("Click Failed, Attempting to click by scrolling into view with top align option");
scrollIntoView(true);
m_element.click();
} catch (WebDriverException e2) {
try {
logger.debug("Click Failed, Attempting to click by scrolling down by 200 pixels");
m_jsDriver.executeScript("window.scrollBy(0,200)");
m_element.click();
} catch (WebDriverException e3) {
logger.debug("Click Failed, Attempting to click by scrolling up by 200 pixels");
m_jsDriver.executeScript("window.scrollBy(0,-200)");
m_element.click();
}
}
}
}
}
}