Module 17 Excercise 9 dice.com | Selenium Forum
M
Posted on 06/07/2016
solution :

package excercise;

import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Assert;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

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


driver.get("http://www.dice.com");
driver.findElement(By.xpath("//*[@id='search-field-keyword']")).sendKeys("java");
driver.findElement(By.xpath("//*[@id='search-field-keyword']")).sendKeys(Keys.ENTER);

Thread.sleep(3000);
//to close job alert page
driver.findElement(By.xpath("//*[@id='myModal']/div/div/div[1]/button")).click();//*[@id="myModal"]/div/div/div[1]/button
// to print first page list
List<WebElement> list=driver.findElements(By.xpath("//div[@class='col-md-9']/div[@id='serp']/div"));
System.out.println(list.size());
for(int j=1;j<list.size();j++)
{
String s= driver.findElement(By.xpath("//h3/a[@id='position"+(j-1)+"']")).getText();
System.out.println("******"+s);
System.out.println(j);

String[] arr = s.split("\\W+");
for ( String ss : arr)
{
//System.out.println(ss);
if(ss.equals("Java"))
{
// System.out.println("found java word");
Assert.assertEquals("Java",ss);
}
}
}

for(int i=2;i<=5;i++)
{
driver.findElement(By.xpath("//div[@id='dice_paging_top']/ul/li/a[text()='"+i+"']")).click();

List<WebElement> list1=driver.findElements(By.xpath("//div[@class='col-md-9']/div[@id='serp']/div"));
System.out.println(list1.size());
for(int j=1;j<=list1.size();j++)
{
String s= driver.findElement(By.xpath("//h3/a[@id='position"+(j-1)+"']")).getText();
System.out.println("******"+s);
System.out.println(j);


//Check if java word is reflected in each of the phrases under Job Title
String[] arr = s.split("\\W+");
for ( String ss : arr)
{

if(ss.equals("Java"))
{
// System.out.println("found java word");
Assert.assertEquals("Java",ss);
}
}


}


}




}

}



/*Pattern pattern = Pattern.compile("\\w+");
Matcher matcher = pattern.matcher(s);
while (matcher.find())
{
System.out.println(matcher.group());
Assert.assertEquals("java", matcher.group());

}*/