Reputation: 47
Performing actions on Chrome using WebDriver
I have a webpage with .xqy extension. where I perform some actions and open the first frame. Then after doing some actions on the first frame I open a second frame and then a third frame. Now, I need to perform something on the first frame so I close the third frame where selenium's focus is currently on and then the second frame by using the following code:
WebDriver dObjExit = driverObj.switchTo().frame(driverObj.findElement(By.xpath("html/body/div[4]/iframe"))).switchTo().frame(driverObj.findElement(By.xpath("//body[@class='dlg-page']/div[4]/iframe")));
dObjExit.findElement(By.xpath("//p[@class='modal-footer']/button")).click();
Now, I'm just left with the first frame and I use the following code to click upon an element on it:
WebDriver dObjExit1 = driverObj.switchTo().parentFrame();
ObjExit1.findElement(By.xpath("//button[@id='srch-save']")).click();
But Selenium throws the following error:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (54, 88). Other element would receive the click:
Any idea about the resolution? Also tried using Actions class but to no avail.
Upvotes: 0
Views: 11024
Reputation: 670
You can write 2 methods before line with error, to wait for page to be loaded and all ajax are executed, eg:
public static void waitForPageLoaded() {
ExpectedCondition<Boolean> expectationLoad = new
ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) driver).executeScript("return document.readyState").toString().equals("complete");
}
};
try {
Thread.sleep(250);
WebDriverWait waitForLoad = new WebDriverWait(driver, 33);
waitForLoad.until(expectationLoad);
} catch (Throwable error) {
Assert.fail("Timeout waiting for Page Load Request to complete.");
}
}
public static void waitForAjaxFinished() {
ExpectedCondition<Boolean> expectationAjax = new
ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((Boolean)((JavascriptExecutor)driver).executeScript("return jQuery.active == 0"));
}
};
try {
Thread.sleep(250);
WebDriverWait waitForAjax = new WebDriverWait(driver, 33);
waitForAjax.until(expectationAjax);
} catch (Throwable error) {
Assert.fail("Timeout waiting for Ajax Finished to complete.");
}
}
Upvotes: 1
Reputation: 17593
Use JavascriptExecutor to overcome from this issue:-
WebElement element= driver.findElement(By.xpath("YOUR XPATH"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Upvotes: 5