Module 17 dice | Selenium Forum
M
Posted on 23/06/2016
when page loads it gives alerts/frames which is blocking further code to be executes

import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Dice {

static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\sunita_java\\driverExe\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);

driver.get("https://www.dice.com");
driver.findElement(By.xpath("//input[@id='search-field-keyword']")).sendKeys("selenium");
driver.findElement(By.xpath("//*[@id='search-form']/fieldset/div[4]/div/div[1]/button")).click();




Set<String> windowId= driver.getWindowHandles();
System.out.println("Total Window size :"+windowId.size());
if(windowId.size()==2)
{
System.out.println("popup present");
Iterator<String> it=windowId.iterator();
System.out.println(it.next());
}else {
System.out.println("popups not present");
}
int i=2;
while(isElementPresent("//*[@id='dice_paging_top']/ul/li[1]/a[@text='"+i+"']"))
{
driver.findElement(By.xpath("//*[@id='dice_paging_top']/ul/li[1]/a[@text='"+i+"']")).click();
i++;
}

}


public static boolean isElementPresent(String xpath){

int count=driver.findElements(By.xpath(xpath)).size();
if(count==0)
return false;
else
return true;

}
}

M
Replied on 23/06/2016

Switch to frames/alert , close it and return


M
Replied on 27/06/2016

i looked for iframe in source code , but coudnt find it ... also tried alert and is not getting close

plz help me where i m going wrong


M
Replied on 28/06/2016

i'm not getting that alert.


M
Replied on 29/06/2016

oh ok... thank