Reputation: 135
I've encountered a problem with FireFox/IE9 driver with selenium. When I use the Actions class of selenium and use its method moveToElement, it wont move to the element and it would return a MoveTargetOutOfBoundsException. I've tried to used others solutions like using Coordinates, Point and javascriptexecutor and all of them didn't worked. By using the moveToElement, It worked on my chrome driver so i don't know why it wont work on firefox33/IE9 as they are native to selenium
Here is my snippet of the code:
WebElement requiredCheckbox = new WebDriverWait(driver,15).until(ExpectedConditions.presenceOfElementLocated(By.name("tc_n_cs_subscribe_1")));
// Point points = requiredCheckbox.getLocation();
// System.out.println(points.getX());
// System.out.println(points.getY());
// actions.moveByOffset(points.getX(), points.getY()).perform();
// ((JavascriptExecutor)
// driver).executeScript("window.scrollBy(0, "+points.getY()+");");
// ((JavascriptExecutor) driver).executeScript(
// "arguments[0].scrollIntoView();", requiredCheckbox);
// Coordinates coordinate =
// ((Locatable)requiredCheckbox).getCoordinates();
// coordinate.onPage();
// coordinate.inViewPort();
actions.moveToElement(requiredCheckbox).build().perform();
requiredCheckbox.click();
Upvotes: 0
Views: 1367
Reputation: 135
I've solved this. I used the javascriptexecutor code.
((JavascriptExecutor) driver).executeScript(
"arguments[0].scrollIntoView();", requiredCheckbox);
It worked after I added DesiredCapabilities setJavascriptEnabled method.
Upvotes: 0
Reputation: 131
What are you trying to do? If you want to scroll the view to requiredCheckbox, try
((Locatable) requiredCheckbox).getCoordinates().inViewPort();
Upvotes: 0