You say you tried explicit wait, but it looks like what you are asking for can be best done with fluentWait (which is a type of explicit wait):
public WebElement fluentWait(final By locator) { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); WebElement foo = wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return driver.findElement(locator); } }); return foo; };;
Here WebElement will be the button you are trying to click. The cool thing about FluentWait is that the item itself is returned if it is found. From the documentation:
Implementation of the Wait interface, which can have its own timeout and polling interval, configured on the fly. Each FluentWait instance determines the maximum timeout for the condition, as well as the frequency of the status check. In addition, the user can configure wait to ignore certain types of exceptions while waiting, such as NoSuchElementExceptions when searching for an element on the page.
To use it, simply do:
WebElement newListBtn = fluentWait(By.id("button"));
Also try:
Driver.SwitchTo().DefaultContent();
before clicking if it is a frame problem.
source share