How to use ElementClickInterceptedException class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.ElementClickInterceptedException

ElementClickInterceptedException org.openqa.selenium.ElementClickInterceptedException

Most of the time, ElementClickInterceptedException raised due to any other dom element is overlaying/obscuring the element that need to be clicked.

copy
1Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: 2element click intercepted: 3Element <input value="Google Search" aria-label="Google Search" name="btnK" type="submit"> 4 is not clickable at point (596, 368). 5Other element would receive the click: <span>...</span>

Example

It is an example code for clicking an element using javascript executor rather using Selenium based click method to avoid ElementClickInterceptedException

copy
1public static void main(String[] args) throws Exception { 2 System.setProperty("webdriver.chrome.driver", "D:\PATH\chromedriver.exe"); 3 WebDriver driver = new ChromeDriver(); 4 driver.manage().window().maximize(); 5 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 6 driver.get("https://google.com"); 7 8 driver.findElement(By.name("q")).sendKeys("facebook"); 9 WebElement searchButton = driver.findElement(By.xpath("(//input[@value='Google Search'])[2]")); 10 JavascriptExecutor js = (JavascriptExecutor)driver; 11 js.executeScript("arguments[0].click()", searchButton); 12}

Solutions

  • Add wait as sometime websites are not fully loaded
  • Check network speed which may cause the website rendering slow
  • Check any overlaying dom element which block click action to the target element
  • Use Javascript executor to click the element

Code Snippets

Here are code snippets that can help you understand more how developers are using

Source:WebUtility.java Github

copy

Full Screen

2import java.time.Duration;3import java.util.List;4import java.util.function.Function;5import org.openqa.selenium.By;6import org.openqa.selenium.ElementClickInterceptedException;7import org.openqa.selenium.JavascriptExecutor;8import org.openqa.selenium.Keys;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.interactions.Actions;12import org.openqa.selenium.support.ui.ExpectedConditions;13import org.openqa.selenium.support.ui.FluentWait;14import org.openqa.selenium.support.ui.Select;15import org.openqa.selenium.support.ui.WebDriverWait;16import com.atmecs.ToolsninjaAutomation.constants.FilePath;17/**18 * Class contains methods of different functionalities used in web testing19 */20public class WebUtility {21 /**22 * method click the Element using the fluent wait concepts ignoring the23 * ElementClickInterceptedException.24 * 25 * @param driver26 * @param xpath27 */28 static WebElement element;29 static List<WebElement> elements;30 WebDriver driver;31 Actions action;32 public WebUtility(WebDriver driver) {33 this.driver = driver;34 action = new Actions(driver);35 }36 public WebElement selectSelectorType(String locator) {37 String[] locatorsPart = locator.split(";");38 switch (locatorsPart[0].toUpperCase()) {39 case "ID": {40 element = driver.findElement(By.id(locatorsPart[1]));41 break;42 }43 case "NAME": {44 element = driver.findElement(By.name(locatorsPart[1]));45 break;46 }47 case "CLASS": {48 element = driver.findElement(By.className(locatorsPart[1]));49 break;50 }51 case "LINK_TEXT": {52 element = driver.findElement(By.linkText(locatorsPart[1]));53 break;54 }55 case "PARTIAL_LINK_TEXT": {56 element = driver.findElement(By.partialLinkText(locatorsPart[1]));57 break;58 }59 case "TAG_NAME": {60 element = driver.findElement(By.tagName(locatorsPart[1]));61 break;62 }63 case "CSS": {64 // System.out.println("css");65 element = driver.findElement(By.cssSelector(locatorsPart[1]));66 break;67 }68 case "XPATH": {69 element = driver.findElement(By.xpath(locatorsPart[1]));70 break;71 }72 default: {73 System.out.println("Selector not found");74 }75 }76 return element;77 }78 /**79 * method click the Element using the fluent wait concepts ignoring the80 * ElementClickInterceptedException.81 *82 * @param locator83 */84 public void clickElement(String locator) {85 selectSelectorType(locator);86 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)87 .ignoring(ElementClickInterceptedException.class).pollingEvery(Duration.ofSeconds(2))88 .withTimeout(Duration.ofSeconds(30));89 fluentWait.until(new Function<WebDriver, Boolean>() {90 public Boolean apply(WebDriver driver) {91 WebElement element = selectSelectorType(locator);92 element.click();93 return true;94 }95 });96 }97 /**98 * method select the dropdown and select the Element by visible text, using the99 * fluent wait concepts ignoring the ElementClickInterceptedException.100 * 101 * @param locator102 */103 public void selectDropdown(String locator, String text) {104 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)105 .ignoring(ElementClickInterceptedException.class).pollingEvery(Duration.ofSeconds(2))106 .withTimeout(Duration.ofSeconds(30));107 fluentWait.until(new Function<WebDriver, Boolean>() {108 public Boolean apply(WebDriver driver) {109 WebElement element = selectSelectorType(locator);110 Select trip = new Select(element);111 trip.selectByVisibleText(text);112 return true;113 }114 });115 }116 /**117 * method click the blank fields and send the text to be entered118 * 119 * @param locator120 * @param text121 */122 public void clickAndSendText(String locator, String text) {123 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)124 .ignoring(ElementClickInterceptedException.class).pollingEvery(Duration.ofSeconds(2))125 .withTimeout(Duration.ofSeconds(30));126 fluentWait.until(new Function<WebDriver, Boolean>() {127 public Boolean apply(WebDriver driver) {128 WebElement element = selectSelectorType(locator);129 element.sendKeys(text);130 ;131 return true;132 }133 });134 }135 public String getText(String locator) {136 WebElement element = selectSelectorType(locator);137 String text = element.getText();138 return text;139 }140 /**141 * method takes parameters as142 * 143 * @param locator144 * @return element on the web page145 */146 public WebElement getElement(String locator) {147 WebElement element = selectSelectorType(locator);148 return element;149 }150 /**151 * method takes parameters as152 * 153 * @param locatorIsDisplayed154 * @return a boolean value for the displayed element on the web page155 */156 public boolean isDisplayed(String locatorIsDisplayed) {157 boolean isDisplayed = false;158 try {159 isDisplayed = selectSelectorType(locatorIsDisplayed).isDisplayed();160 } catch (Exception e) {161 isDisplayed = false;162 }163 return isDisplayed;164 }165 /**166 * method takes parameters as167 * 168 * @param locatorIsSelected169 * @return a boolean value for the selected element on the web page170 */171 public boolean isSelected(String locatorIsSelected) {172 boolean isSelected = false;173 try {174 isSelected = selectSelectorType(locatorIsSelected).isSelected();175 } catch (Exception e) {176 isSelected = false;177 }178 return isSelected;179 }180 /**181 * method takes parameters as182 * 183 * @param locator and uses the explicit wait concept184 * @return a boolean value after checking the visibility of the.185 */186 public boolean isElementVisible(String locator) {187 WebDriverWait wait = new WebDriverWait(driver, 15);188 try {189 wait.until(ExpectedConditions.visibilityOf(selectSelectorType(locator)));190 } catch (Exception exception) {191 return false;192 }193 return true;194 }195 /**196 * method takes parameters as197 * 198 * @param xpath199 * @return the list of elements200 */201 public List<WebElement> getElementsList(String locator) {202 System.out.println(locator);203 String[] locatorsPart = locator.split(";");204 System.out.println(locatorsPart[0]);205 System.out.println(locatorsPart[1]);206 switch (locatorsPart[0]) {207 case "ID": {208 System.out.println("ID");209 elements = driver.findElements(By.id(locatorsPart[1]));210 break;211 }212 case "NAME": {213 System.out.println("name");214 elements = driver.findElements(By.name(locatorsPart[1]));215 break;216 }217 case "CLASS": {218 System.out.println("class");219 elements = driver.findElements(By.className(locatorsPart[1]));220 break;221 }222 case "LINK_TEXT": {223 System.out.println("link");224 elements = driver.findElements(By.linkText(locatorsPart[1]));225 break;226 }227 case "PARTIAL_LINK_TEXT": {228 System.out.println("parftial");229 elements = driver.findElements(By.partialLinkText(locatorsPart[1]));230 break;231 }232 case "TAG_NAME": {233 System.out.println("tag_name");234 elements = driver.findElements(By.tagName(locatorsPart[1]));235 break;236 }237 case "CSS": {238 System.out.println("css");239 elements = driver.findElements(By.cssSelector(locatorsPart[1]));240 break;241 }242 case "XPATH": {243 System.out.println("xpath");244 elements = driver.findElements(By.xpath(locatorsPart[1]));245 break;246 }247 default: {248 System.out.println("Getting elements with this Selector is not available");249 }250 }251 return elements;252 }253 /**254 * method scroll down the window on the web page255 * 256 * @param horizontal index257 * @param vertical index258 */259 public void scrollDownPage(int horizontalIndex, int verticalIndex) {260 JavascriptExecutor js = (JavascriptExecutor) driver;261 String scroll = "window.scrollBy(" + horizontalIndex + "," + verticalIndex + ")";262 js.executeScript(scroll);263 }264 /**265 * In this method, mouse over operation of the mouse is done266 * 267 * @param locator268 */269 public void action(String locator) {270 try {271 Thread.sleep(2000);272 } catch (InterruptedException e) {273 System.out.println("System interrupted");274 }275 WebElement element = selectSelectorType(locator);276 action.moveToElement(element).build().perform();277 }278 /**279 * In this method,Input boxes entered texts are cleared280 * 281 * @param locator282 */283 public void clearField(String locator) {284 selectSelectorType(locator).clear();285 }286 /**287 * Method gets the title of the current page288 */289 public String getTitle() {290 String title = driver.getTitle();291 return title;292 }293 /**294 * Method waits for the time until the xpath of the element is clickable295 * 296 * @param locator297 */298 public void explicitWait(String locator) {299 WebDriverWait wait = new WebDriverWait(driver, FilePath.TIMEOUT_INSECONDS);300 wait.until(ExpectedConditions.elementToBeClickable(selectSelectorType(locator)));301 }302 /**303 * Method scrolls down the window resolution until the view of webelement is not304 * found305 * 306 * @param locator307 */308 public void scrollIntoview(String locator) {309 WebElement element = selectSelectorType(locator);310 JavascriptExecutor je = (JavascriptExecutor) driver;311 je.executeScript("arguments[0].scrollIntoView(true);", element);312 }313 /**314 * Method gets the attribute of the web element315 * 316 * @param locator317 * @param attribute318 */319 public String getAttribute(String locator, String attribute) {320 WebElement element = selectSelectorType(locator);321 String value = element.getAttribute(attribute);322 return value;323 }324 /**325 * Method gets the attribute of the web element326 * 327 * @param locator328 */329 public void scrollByTimeout(String locator) {330 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)331 .ignoring(ElementClickInterceptedException.class).pollingEvery(Duration.ofSeconds(3))332 .withTimeout(Duration.ofSeconds(90));333 fluentWait.until(new Function<WebDriver, Boolean>() {334 public Boolean apply(WebDriver driver) {335 action.sendKeys(Keys.SPACE);336 scrollDownPage(0, -300);337 WebElement element = selectSelectorType(locator);338 element.click();339 return true;340 }341 });342 }343 /**344 * method select the dropdown and select the Element by index, using the fluent345 * wait concepts ignoring the ElementClickInterceptedException.346 * 347 * @param index348 * @param locator349 */350 public void selectDropdownByIndex(String locator, int index) {351 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)352 .ignoring(ElementClickInterceptedException.class).pollingEvery(Duration.ofSeconds(2))353 .withTimeout(Duration.ofSeconds(30));354 fluentWait.until(new Function<WebDriver, Boolean>() {355 public Boolean apply(WebDriver driver) {356 WebElement element = selectSelectorType(locator);357 Select trip = new Select(element);358 trip.selectByIndex(index);359 return true;360 }361 });362 }363 /**364 * Method sets the attribute value of the web element365 * 366 * @param locator...

Full Screen

Full Screen

Source:ActionExtension.java Github

copy

Full Screen

1package utilPackage;2import org.openqa.selenium.By;3import org.openqa.selenium.ElementClickInterceptedException;4import org.openqa.selenium.JavascriptExecutor;5import org.openqa.selenium.Keys;6import org.openqa.selenium.NoSuchElementException;7import org.openqa.selenium.Point;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.WebDriverException;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.interactions.Actions;12public class ActionExtension extends baseclass{13 final static int RetryCount=13;14 15 public static void SafeClick(WebElement webElement) 16 {17 try18 {19 try20 {21 TryByClicking(webElement);22 }23 catch (ElementClickInterceptedException elementClickInterceptedException)24 {25 try26 {27 TryByHittingEnterKey(webElement);28 }29 catch (ElementClickInterceptedException elClickInterceptedException)30 {31 TryByMovingTop(webElement);32 }33 }34 catch (NoSuchElementException noSuchElementException)35 {36 wait(3);37 }38 }39 catch(WebDriverException webDriverException)40 {41 // Known issue42 // Page request timeout : Page is not loaded after clicking on element43 }44 45 46 }47 48 private static void TryByMovingTop(WebElement webElement)49 {50 try51 {52 MoveToElement(webElement);53 webElement.click();54 }55 catch(Exception ex)56 {57 MoveToElement(webElement);58 webElement.click();59 }60 }61 62 private static void TryByHittingEnterKey(WebElement webElement)63 {64 try65 {66 webElement.sendKeys(Keys.ENTER);67 }68 catch (ElementClickInterceptedException elementClickInterceptedException)69 {70 MoveToElement(webElement);71 webElement.sendKeys(Keys.ENTER);72 }73 }74 75 private static void TryByClicking(WebElement webElement)76 {77 try78 {79 webElement.click();80 }81 catch (Exception ex)82 {83 try84 {85 MoveToElement(webElement);86 webElement.click();87 }88 catch (Exception ex1)89 {90 ScrollToElement(webElement);91 webElement.click();92 }93 }94 }95 96 public static void MoveToElement(WebElement iWebElement)97 {98 Point classname = iWebElement.getLocation();99 int xElem = classname.getX();100 int yElem = classname.getY();101 String moveToJs = "javascript:window.scrollTo(" + xElem + "," + yElem + ")"; 102 JavascriptExecutor js = (JavascriptExecutor) driver; 103 js.executeScript(moveToJs);104 }105 public static void ScrollToElement(WebElement iWebElement)106 {107 JavascriptExecutor js = (JavascriptExecutor) driver; 108 js.executeScript("arguments[0].scrollIntoView(false);");109 }110 111 public static WebElement SafeFindElement(WebDriver webDriver, By elementLocator) 112 {113 114 for (int i = 1; i <= RetryCount; i++)115 {116 try117 {118 return webDriver.findElement(elementLocator);119 }120 catch (NoSuchElementException noException)121 {122 wait(i);123 124 }125 }126 return webDriver.findElement(elementLocator);127 }128 129 public static void SafeEnterText(WebElement webElement, String text)130 {131 try132 {133 webElement.clear();134 webElement.sendKeys(text);135 }136 catch (ElementClickInterceptedException elException)137 {138 MoveToElement(webElement);139 webElement.clear();140 webElement.sendKeys(text);141 }142 }143 144 public static void wait(int i) 145 {146 int sleepTime = 1000 * i;147 try {148 Thread.sleep(sleepTime);149 } 150 catch (InterruptedException e) {...

Full Screen

Full Screen

Source:BaseClass.java Github

copy

Full Screen

...10import javax.annotation.Nonnull;1112import org.apache.log4j.Logger;13import org.openqa.selenium.Alert;14import org.openqa.selenium.ElementClickInterceptedException;15import org.openqa.selenium.JavascriptExecutor;16import org.openqa.selenium.NoAlertPresentException;17import org.openqa.selenium.NoSuchElementException;18import org.openqa.selenium.StaleElementReferenceException;19import org.openqa.selenium.TimeoutException;20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.WebDriverException;22import org.openqa.selenium.WebElement;23import org.openqa.selenium.interactions.Actions;24import org.openqa.selenium.support.ui.ExpectedCondition;25import org.openqa.selenium.support.ui.ExpectedConditions;26import org.openqa.selenium.support.ui.WebDriverWait;2728public class BaseClass {29 static Logger logger = Logger.getLogger("BaseClass");30 public static WebDriver driver;31 public static boolean bResult;32 public BaseClass(WebDriver driver){33 BaseClass.driver = driver;34 BaseClass.bResult = true;35 }36 37 // This method wait till entire DOM gets loaded completely38 public static void waitForContent() {39 ExpectedCondition<Boolean> loaded = new ExpectedCondition<Boolean>() {40 @Override41 public Boolean apply(@Nonnull WebDriver driver) {42 String result = "return ((document.readyState === 'complete') && ($.active == 0))";43 return (Boolean) ((JavascriptExecutor) driver).executeScript(result);44 }45 };46 try {47 new WebDriverWait(BaseClass.driver, 100).until(loaded);48 } catch (WebDriverException e) {49 loaded = new ExpectedCondition<Boolean>() {50 @Override51 public Boolean apply(@Nonnull WebDriver driver) {52 String result = "return ((document.readyState === 'complete'))";53 return (Boolean) ((JavascriptExecutor) driver).executeScript(result);54 }55 };56 new WebDriverWait(BaseClass.driver, 100).until(loaded);57 }58 }5960 public static WebElement getElement(WebElement element) {61 WebDriverWait wait = (WebDriverWait) new WebDriverWait(driver, 50).ignoring(StaleElementReferenceException.class);62 waitForContent();63 wait.until(ExpectedConditions.visibilityOf(element));64 WebElement ele = wait.until(ExpectedConditions.elementToBeClickable(element));65 return ele;66 }6768 // This method gives random number69 static Random randNum = new Random();70 static Set<Integer> jobSet = new LinkedHashSet<Integer>();71 static List<Integer> list = new ArrayList<Integer>();7273 public static int getRandomNumber(int maxRange) {7475 while (jobSet.size() < maxRange) {76 jobSet.add(randNum.nextInt(maxRange) + 1);7778 }79 // Generic function to convert set to list80 list.addAll(jobSet);8182 Collections.shuffle(list);83 int randomNo = list.stream().findAny().get();84 return randomNo;85 }8687 // This method to be used for the element which frequently gets changed in DOM88 // and gives StaleElementReferenceException89 public static boolean retryingClick(WebElement ele) {90 boolean result = false;91 int attempts = 0;92 while (attempts < 20) {93 try {94 waitForContent();95 retryingFindElement(ele);96 ele.click();97 result = true;98 break;99 } catch (NoSuchElementException e) {100101 logger.info("Refinding the element as its throwing NoSuchElementException");102103 } catch (ElementClickInterceptedException e) {104105 logger.info("Refinding the element as its throwing ElementClickInterceptedException");106107 } catch (StaleElementReferenceException e) {108109 logger.info("Refinding the element as its throwing StaleElementReferenceException");110111 } catch (TimeoutException e) {112113 logger.info("Refinding the element as its throwing TimeoutException");114115 } catch (Exception e) {116117 logger.info("Refinding the element as its throwing exception");118 }119 waitForContent();120 attempts++;121 }122 return result;123 }124125 // This method to be used for the element which frequently gets changed in DOM126 // and gives NoSuchElementException127 public static boolean retryingFindElement(WebElement ele) {128 boolean result = false;129 int attempts = 0;130 while (attempts < 20) {131 try {132 waitForContent();133 ele.isDisplayed();134 result = true;135 break;136 } catch (NoSuchElementException e) {137138 logger.info("Refinding the element as its throwing NoSuchElementException");139140 } catch (ElementClickInterceptedException e) {141142 logger.info("Refinding the element as its throwing ElementClickInterceptedException");143144 } catch (StaleElementReferenceException e) {145146 logger.info("Refinding the element as its throwing StaleElementReferenceException");147148 } catch (TimeoutException e) {149150 logger.info("Refinding the element as its throwing TimeoutException");151152 } catch (Exception e) {153154 logger.info("Refinding the element as its throwing exception");155 }156 waitForContent(); ...

Full Screen

Full Screen

Source:CommonUtility.java Github

copy

Full Screen

2import java.util.List;3import java.util.concurrent.TimeUnit;4import java.util.function.Function;5import org.openqa.selenium.By;6import org.openqa.selenium.ElementClickInterceptedException;7import org.openqa.selenium.JavascriptExecutor;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.support.ui.ExpectedConditions;11import org.openqa.selenium.support.ui.FluentWait;12import org.openqa.selenium.support.ui.Select;13import org.openqa.selenium.support.ui.WebDriverWait;14public class CommonUtility {15 /**16 * method click the Element using the fluent wait concepts ignoring the17 * ElementClickInterceptedException.18 * 19 * @param driver20 * @param xpath21 */22 public static void clickElement(WebDriver driver, final String xpath) {23 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)24 .ignoring(ElementClickInterceptedException.class).pollingEvery(1, TimeUnit.SECONDS)25 .withTimeout(30, TimeUnit.SECONDS);26 fluentWait.until(new Function<WebDriver, Boolean>() {27 public Boolean apply(WebDriver driver) {28 WebElement element = driver.findElement(By.xpath(xpath));29 element.click();30 return true;31 }32 });33 }34 public static void selectDropdown(WebDriver driver, final String xpath, int timeOut, final String text) {35 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).pollingEvery(1, TimeUnit.SECONDS)36 .withTimeout(30, TimeUnit.SECONDS);37 fluentWait.until(new Function<WebDriver, Boolean>() {38 public Boolean apply(WebDriver driver) {39 WebElement element = driver.findElement(By.xpath(xpath));40 Select trip = new Select(element);41 trip.selectByVisibleText(text);42 return true;43 }44 });45 }46 /**47 * method click the blank fields and send the text to be entered48 * 49 * @param driver50 * @param xpath51 * @param timeOutInSeconds52 * @param text53 */54 public static void clickAndSendText(WebDriver driver, final String xpath, int timeOutInSeconds, final String text) {55 FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)56 .ignoring(ElementClickInterceptedException.class).pollingEvery(1, TimeUnit.SECONDS)57 .withTimeout(timeOutInSeconds, TimeUnit.SECONDS);58 fluentWait.until(new Function<WebDriver, Boolean>() {59 public Boolean apply(WebDriver driver) {60 WebElement element = driver.findElement(By.xpath(xpath));61 element.sendKeys(text);62 ;63 return true;64 }65 });66 }67 public static WebElement getElement(WebDriver driver, String xpath, String text) {68 WebElement element = driver.findElement(By.xpath(xpath));69 element.sendKeys(text);70 return element;...

Full Screen

Full Screen

Source:LoginSteps.java Github

copy

Full Screen

...16 public void click_on_sign_In_button() throws Throwable {17 try {18 //webDriver.wait(12);19 webDriver.findElement(By.xpath("//*[@id=\"sign_in_btn_link\"]")).click();20 } catch (org.openqa.selenium.ElementClickInterceptedException e) {21 System.out.print(e);22 }23 }24 @Then("^user should be able to see the signIn popup window with options$")25 public void user_should_be_able_to_see_the_signIn_popup_window_with_options() throws Throwable {26 try {27 String headerValue = webDriver.findElement(By.xpath("//*[@id=\"sign_in_btn_link\"]")).getText();28 } catch (org.openqa.selenium.ElementClickInterceptedException e) {29 System.out.print(e);30 }31 }32 @Given("^navigate to sign In button and click$")33 public void navigate_to_sign_In_button_and_click() throws Throwable {34 System.out.print("Navigate the sign in button and click");35 }36 @When("^signIn popup window opens$")37 public void signin_popup_window_opens() throws Throwable {38 System.out.print("Sign in popup window open");39 }40 @When("^enter valid email as \"([^\"]*)\" and password as \"([^\"]*)\"$")41 public void enter_valid_email_as_and_password_as(String arg1, String arg2) throws Throwable {42 try {43 webDriver.findElement(By.xpath("//*[@id=\"sign_in_email\"]/input"))44 .sendKeys(DriverInitializer.getProperty("username"));45 webDriver.findElement(By.xpath("//*[@id=\"mysecretpassword\"]"))46 .sendKeys(DriverInitializer.getProperty("password"));47 } catch (org.openqa.selenium.ElementClickInterceptedException e) {48 System.out.print(e);49 }50 }51 @When("^click on sign In button on the sign in modal$")52 public void click_on_sign_In_button_on_the_sign_in_modal() throws Throwable {53 try {54 webDriver.findElement(By.xpath("//*[@id=\"sign_in_btn\"]")).click();55 } catch (org.openqa.selenium.ElementClickInterceptedException e) {56 System.out.print(e);57 }58 }59 @Then("^user should be able to see the home page$")60 public void user_should_be_able_to_see_the_home_page() throws Throwable {61 try {62 webDriver.wait(12);63 webDriver.findElement(By.id("navigate_linkTo_userProfile"));64 webDriver.quit();65 } catch (org.openqa.selenium.ElementClickInterceptedException e) {66 System.out.print(e);67 }68 }69}...

Full Screen

Full Screen

Source:GenericPage.java Github

copy

Full Screen

1package pages;2import net.serenitybdd.core.pages.PageObject;3import org.openqa.selenium.ElementClickInterceptedException;4import org.openqa.selenium.JavascriptExecutor;5import org.openqa.selenium.NoSuchElementException;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.support.FindBy;8import org.openqa.selenium.support.ui.ExpectedConditions;9import org.openqa.selenium.support.ui.FluentWait;10import java.time.Duration;11import static java.time.Duration.ofMillis;12public class GenericPage extends PageObject {13 @FindBy(css = "button.js-accept")14 WebElement acceptCookiePolicyButton;15 @FindBy(css = "button.js-dismiss-login-notice-btn")16 WebElement closeLoginNoticeBanner;17 FluentWait globalFluentWait(int timeOutSeconds, int pollingEveryMilliseconds) {18 return new FluentWait<>(getDriver())19 .withTimeout(Duration.ofSeconds(timeOutSeconds))20 .pollingEvery(ofMillis(pollingEveryMilliseconds))21 .ignoring(NoSuchElementException.class);22 }23 public void acceptCookiePolicy() {24 globalFluentWait(10, 100).until(ExpectedConditions.visibilityOf(25 acceptCookiePolicyButton));26 globalFluentWait(10, 100).until(ExpectedConditions.elementToBeClickable(27 acceptCookiePolicyButton));28 try {29 acceptCookiePolicyButton.click();30 } catch (ElementClickInterceptedException e) {31 JavascriptExecutor js = (JavascriptExecutor) getDriver();32 js.executeScript("document.querySelector('button.js-accept').click()");33 }34 }35 public void closeLoginNoticeBanner() {36 try {37 closeLoginNoticeBanner.click();38 } catch (ElementClickInterceptedException e) {39 JavascriptExecutor js = (JavascriptExecutor) getDriver();40 js.executeScript("document.querySelector('button.js-dismiss-login-notice-btn').click()");41 }42 }43}

Full Screen

Full Screen

Source:RequestLoansPage.java Github

copy

Full Screen

1package setltestPOMSelbank;2import org.openqa.selenium.ElementClickInterceptedException;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.support.FindBy;6import org.openqa.selenium.support.PageFactory;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9public class RequestLoansPage {10public RequestLoansPage(WebDriver driver){11PageFactory.initElements(driver, this);12 }13@FindBy(xpath = "//input[contains(@ng-model,'loanRequest.amount')]")14 private WebElement loanAmountTextBox;15 16@FindBy(xpath = "//input[contains(@ng-model,'loanRequest.downPayment')]")17 private WebElement downPaymentTextBox;18 19@FindBy(xpath = "//input[contains(@value,'Apply Now')]")20 private WebElement applyNowButton;21 22 public void setLoanAmountField(String text) {23 loanAmountTextBox.sendKeys(text);24 }25 public void setDownPaymentField(String text) {26 downPaymentTextBox.sendKeys(text);27 }28 public void applyNowClickButton() {29 applyNowButton.click();30 } 31 public void loanAmountWait(WebDriver driver) {32 new WebDriverWait(driver, 60).until(ExpectedConditions.elementToBeClickable(loanAmountTextBox));33 }34 public void downPaymentWait(WebDriver driver) {35 new WebDriverWait(driver, 60).until(ExpectedConditions.elementToBeClickable(downPaymentTextBox));36 }37 public void clickApplyNowWait(WebDriver driver) {38 new WebDriverWait(driver, 60).ignoring(ElementClickInterceptedException.class).until(d -> {39 applyNowButton.click();40 return true;41 42 });43 }44}45 ...

Full Screen

Full Screen

Source:Button.java Github

copy

Full Screen

1package decoratorpattern.seleniumdecorator;2import org.openqa.selenium.ElementClickInterceptedException;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import businesslayer.datamanager.DriverProviderManager;9public class Button extends DecoratorClass{10 public Button(WebElement element) {11 super(element);12 }13 public void clickJS(){14 WebDriver driver = DriverProviderManager.getDriver();15 ((JavascriptExecutor) driver).executeScript("arguments[0].click()", element);16 }17 public void safeClick(){18 WebDriver driver = DriverProviderManager.getDriver();19 try {20 super.click();21 } catch (ElementClickInterceptedException e){22 new WebDriverWait(driver, TIME_TO_WAIT).until(ExpectedConditions.elementToBeClickable(element));23 super.click();24 }25 }26}...

Full Screen

Full Screen

ElementClickInterceptedException

Using AI Code Generation

copy

Full Screen

1package com.selenium;2import org.openqa.selenium.By;3import org.openqa.selenium.ElementClickInterceptedException;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9public class ElementClickInterceptedExceptionDemo {10 public static void main(String[] args) throws InterruptedException {11 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Santosh\\Downloads\\chromedriver_win32\\chromedriver.exe");12 WebDriver driver = new ChromeDriver();13 driver.manage().window().maximize();14 WebDriverWait wait = new WebDriverWait(driver, 10);15 element.click();16 try {17 element1.click();18 } catch (ElementClickInterceptedException e) {

Full Screen

Full Screen

ElementClickInterceptedException

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.By;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.interactions.Actions;6import org.openqa.selenium.JavascriptExecutor;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9import org.openqa.selenium.ElementClickInterceptedException;10import org.openqa.selenium.NoSuchElementException;11import org.openqa.selenium.StaleElementReferenceException;12import org.openqa.selenium.TimeoutException;13public class ElementClickInterceptedExceptionExample {14 public static void main(String[] args) throws InterruptedException {15 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");16 WebDriver driver = new ChromeDriver();17 driver.manage().window().maximize();18 WebElement searchBox = driver.findElement(By.name("q"));19 searchBox.sendKeys("selenium");20 Actions actions = new Actions(driver);21 actions.moveToElement(searchButton).click().perform();22 WebDriverWait wait = new WebDriverWait(driver, 10);23 JavascriptExecutor js = (JavascriptExecutor) driver;24 wait.until(ExpectedConditions.jsReturnsValue("return document.readyState==\"complete\";"));25 String currentURL = driver.getCurrentUrl();26 System.out.println("The current url of the page is " + currentURL);27 String title = driver.getTitle();

Full Screen

Full Screen
copy
1static final Map<String , String> FLAVORS = new HashMap<String , String>() {{2 put("Up", "Down");3 put("Charm", "Strange");4 put("Top", "Bottom");5}};6
Full Screen
copy
1private static final Map<Integer, String> MY_MAP = Map.of(1, "one", 2, "two");2
Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful