Module-13 | Exercise-4 | Selenium Forum
M
Posted on 24/04/2016
Hi,
Im able to select the required option in the list, but Im getting 'null' for getAttribute("checked") for which the option is already selected. Can you please help me out where im doing wrong.

package com.sample;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Jobserve {

public static void main(String[] args) {

WebDriver d = new FirefoxDriver();

d.get("http://www.jobserve.com");

d.manage().window().maximize();

d.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

d.findElement(By.xpath("//span[@id='ddcl-selInd']")).click();

d.findElement(By.xpath("//label[@class='ui-dropdownchecklist-text']")).click();

List<WebElement> options = d.findElements(By.xpath("//div[@id='ddcl-selInd-ddw']/div/div"));

System.out.println(options.size());

String Company = "Education";

for(int i=1;i<options.size();i++){

//System.out.println("Option names: "+options.get(i).getText());

if(Company.equals(options.get(i).getText())){

options.get(i).click();

}

System.out.println(options.get(i).getText()+"---"+options.get(i).getAttribute("checked"));

}

}

}

OUTPUT: Education---null

M
Replied on 26/04/2016

after clicking the education checkbox you need to get the list values again from website.


M
Replied on 26/04/2016

I tried, but still issue exists.


M
Replied on 27/04/2016

package com.sample;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Jobserve {

public static void main(String[] args) {
WebDriver d = new FirefoxDriver();
d.get("http://www.jobserve.com");
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
d.findElement(By.xpath("//span[@id='ddcl-selInd']")).click();
d.findElement(By.xpath("//label[@class='ui-dropdownchecklist-text']"))
.click();
List<WebElement> options = d.findElements(By
.xpath("//div[@id='ddcl-selInd-ddw']/div/div"));
System.out.println(options.size());
String Company = "Education";
for (int i = 1; i < options.size(); i++) {
// System.out.println("Option names: "+options.get(i).getText());
if (Company.equals(options.get(i).getText())) {
options.get(i).click();
}
}
List<WebElement> options1 = d.findElements(By
.xpath("//div[@id='ddcl-selInd-ddw']/div/div/input"));
System.out.println(options1.size());
for (int i = 1; i < options1.size(); i++) {
System.out.println(options.get(i).getText() + "---"
+ options1.get(i).getAttribute("checked"));
}
d.quit();
}
}