Selenium - tips and tricks
- Sarath Babu V S

- Oct 30, 2020
- 1 min read
This blog documents tips and tricks that would be helpful when automating using Selenium tool and we hit a road block in particular cases.
Sometimes clicking a button on a page does not work. Below are suggestions:
Use Explicit wait command to wait till the button is clickable:
wait.until(ExpectedConditions.elementToBeClickable(By.id("button1")))Use Explicit wait command to wait till the button is present on the DOM of a page and visible:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("button1")))Use Javascript code to scroll into the element and click it:
WebElement element = driver.findElement(By.id("button1"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
Use action class double click method:
action.doubleClick(element).build().perform(); Use action class to click, hold and release on the element:
action.ClickAndHold(element).Release().Click().Perform();
Comments