SeleniumWebdriverException issue is
occur only when working with chrome driver as the chrome browser uses the point
location. When the element position is not fixed and we are trying to perform
some action on that particular element will effect/result an error as
'selenium.common.exceptions.WebDriverException - Element is not clickable at
point (12, 585). Other element would receive the click'.
This thing happens
when the element is loaded into the DOM(document object model) but position is
not fixed on the GUI. There may be some div,images or ads that are not being
loaded completely and ChromeDriver always tries to click the middle of the particular
element.
In this case work
around that worked to resolve the given issue. But to make sure that the best
and simple solution is to figure out the exact reason and how to fix the
problem. We need to find out which part of the div and image is taking more
time to download. Before clicking of an element we need to make sure that
element is present in the DOM, visible in the GUI and the last and most is position is fixed. When the element
position is fixed then the problem is being solved. If you want to tweak that,
try with Thread.sleep or verify in to the debug mode in eclapse.
Using Thread.sleep
is not a good idea. Instead we need to go for WebDriverWait ExpectedConditions.
There are many Conditions
that can be use within Webdriver tests.
a.
visibilityOf(WebElement element) : An expectation for check that particular
element, known to be exists on the DOM of a page, is visible.
b. visibilityOfElementLocated(By locator) : An expectation for check that an element is exists on the DOM of a page and its visibility.
b. visibilityOfElementLocated(By locator) : An expectation for check that an element is exists on the DOM of a page and its visibility.
In the above two
conditions we are waiting for an element to be exist on the DOM of a web page
and also its visible. These work fine only when the element is being loaded
completely.
If the element is
being loaded and visible. In chrome driver the position of the element is also necessary.
Point to be noted that will work perfectly on Firefox driver.
Then question is how
to resolved this problem in Chrome browser? Please check the number of comments
and discussions on Chrome
Element is not clickable issue blog
Below
are the different cases that works for people who also face the same type of problem.
1. This is a simple
solution that worked for most of the people. Try to maximize chrome browser
when you are working with resolutions greater than 1024x768.
driver.manage().window().maximize();//maximize the browser
2. The second
solution which also work for few user using through Actions Class
WebElement element = driver.findElement(By("element"));
Actions action = new Actions(driver);
action.moveToElement(element).click().perform();
3. Work for some user
using JavaScriptExecutor. Make sure to import below org.openqa.selenium.JavascriptExecutor;
JavascriptExecutor js = (JavascriptExecutor)driver;
// if element is on top.
js.executeScript("scroll(250, 0)");
//Element is on bottom.
js.executeScript("scroll(0, 250)");
4. It may be also
try the below using X or Y position for points
WebElement element = driver.findElement(By.id(""));
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,"element.getLocation().y+")");// set position
element.click();
Or
WebElement element = driver.findElement(By.id(""));
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,"element.getLocation().y+")");// set position
element.click();
No comments:
Post a Comment