getting thei error:
Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: Element <button id="button1"> is not clickable at point (408,594) because another element <div id="cookie-law-info-bar"> obscures it
code is:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String parentwindow = driver.getWindowHandle();
System.out.println("parent windowhandle is "+ parentwindow);
WebElement clickbutton = driver.findElement(By.id("button1"));
for(int count = 0;count <2;count++)
{
clickbutton.click();
System.out.println("count is " + count );
}
Then I used the Actions class and moveToElement method . Even that method gave this error "MoveTargetOutOfBoundsException"
Error:
Exception in thread "main" org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: (408, 611) is out of bounds of viewport width (1280) and height (607)
Code:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String parentwindow = driver.getWindowHandle();
System.out.println("parent windowhandle is "+ parentwindow);
WebElement clickbutton = driver.findElement(By.id("button1"));
for(int count = 0;count <2;count++)
{
Actions action = new Actions(driver);
action.moveToElement(clickbutton).click().perform();
clickbutton.click();
System.out.println("count is " + count );
}
Then I used the Point class and movetoElement and moveByOffset method.that also gave the error "MoveTargetOutOfBoundsException" error
Error:
Exception in thread "main" org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: (408, 611) is out of bounds of viewport width (1280) and height (607)
Code:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String parentwindow = driver.getWindowHandle();
System.out.println("parent windowhandle is "+ parentwindow);
WebElement clickbutton = driver.findElement(By.id("button1"));
for(int count = 0;count <2;count++)
{
Actions action = new Actions(driver);
Point p = clickbutton.getLocation();
action.moveToElement(clickbutton).moveByOffset(p.y, p.y).click().perform();
clickbutton.click();
System.out.println("count is " + count );
}
Finally the code that worked for me is using the Dimensions class and setting the dimension of the parent window.Below code worked:
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\sudv\\eclipse-workspace\\Selenium\\Drivers\\geckodriver.exe");
WebDriver driver= new FirefoxDriver();
driver.get;
Dimension origsize = driver.manage().window().getSize();
System.out.println("actual main window size is " + origsize);
Dimension dim = new Dimension(500,1000);
//Resize current window to the set dimension
driver.manage().window().setSize(dim);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String parentwindow = driver.getWindowHandle();
System.out.println("parent windowhandle is "+ parentwindow);
WebElement clickbutton = driver.findElement(By.id("button1"));
for(int count = 0;count <2;count++)
{
//Actions action = new Actions(driver);
//action.moveToElement(clickbutton).click().perform();
//Point p = clickbutton.getLocation();
//action.moveToElement(clickbutton).moveByOffset(p.y, p.y).click().perform();
clickbutton.click();
System.out.println("count is " + count );
}
Set<String> allwindows = driver.getWindowHandles();
Iterator<String> i1 = allwindows.iterator();
while(i1.hasNext())
{
String childwindow = i1.next();
if(!parentwindow.equalsIgnoreCase(childwindow))
{
System.out.println("child window is " + childwindow);
driver.switchTo().window(childwindow);
driver.get("
http://www.facebook.com");
}
}
System.out.println("switching to parent window "+parentwindow);
driver.switchTo().window(parentwindow);
driver.manage().window().maximize();
}
}