Meghna
Meghna

Reputation: 9

Selenium web driver - check box not getting clicked

I tried to click on a check box in the link http://www.deal4loans.com/agent.php .But it is not getting checked .Below is my code .For the chcek boxes to appear we need to select 2 nd option from the I am drop down

But I have noticed that if the code is written only to check these check boxes without adding data for all other fields except the check boxes it works .But when we enter data for Name,mail id,Iam ,city,mobile then the Product you deal will not work .

Please help

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Test {
    public static WebDriver driver=new FirefoxDriver();
    public static void main(String[] args)
    {
        driver.get("http://www.deal4loans.com/");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.findElement(By.xpath("html/body/div[4]/div/div/div[1]/a[1]")).click();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);     
     driver.findElement(By.xpath("html/body/div[6]/div[1]/div/div[4]/form/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/input")).sendKeys("Vish");
       driver.findElement(By.xpath("html/body/div[6]/div[1]/div/div[4]/form/table/tbody/tr[3]/td/table/tbody/tr[2]/td[2]/input")).sendKeys("[email protected]");

        Select listbox1 = new Select(driver.findElement(By.xpath("html/body/div[6]/div[1]/div/div[4]/form/table/tbody/tr[3]/td/table/tbody/tr[3]/td[2]/select")));
         listbox1.selectByValue("2");
       Select listbox2 = new Select(driver.findElement(By.xpath("html/body/div[6]/div[1]/div/div[4]/form/table/tbody/tr[3]/td/table/tbody/tr[4]/td[2]/select")));
          listbox2.selectByValue("Chennai");

          driver.findElement(By.xpath("html/body/div[6]/div[1]/div/div[4]/form/table/tbody/tr[3]/td/table/tbody/tr[6]/td[2]/input")).sendKeys("9898765676");

        driver.findElement(By.xpath("//input[@value='Personal Loan']")).click(); 

            driver.findElement(By.xpath("//input[@value='Home Loan']")).click(); 

            driver.findElement(By.xpath("//input[@value='Car Loan']")).click(); 

            driver.findElement(By.xpath("//input[@value='Loan Against Property']")).click(); 

            driver.findElement(By.xpath("//input[@value='Business Loan']")).click();

            driver.findElement(By.xpath("//input[@value='Credit Card']")).click();

    driver.findElement(By.xpath("html/body/div[6]/div[1]/div/div[4]/form/table/tbody/tr[3]/td/table/tbody/tr[9]/td/input")).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     }


     }

Upvotes: 0

Views: 1604

Answers (1)

Subh
Subh

Reputation: 4424

Got the issue!!

There are 2 divs, div with id 'div0' and div with 'div1', with 'display attribute' changing from 'none' to 'block' and they have the same checkboxes with same 'value' attribute, and hence they weren't getting clicked. Below is the image for that Checkbox block:

enter image description here

Below code will work all times, (o'course when the options are displayed). I have also modified your code with relative xpaths for consistency:

WebDriver driver = new FirefoxDriver();

driver.manage().window().maximize();

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

driver.get("http://www.deal4loans.com/");

driver.findElement(By.xpath("//a[.='Agents Login']")).click();

driver.findElement(By.name("From_Name")).sendKeys("Vish");
driver.findElement(By.name("From_Email")).sendKeys("[email protected]");

Select listbox1 = new Select(driver.findElement(By.id("query_type")));
listbox1.selectByValue("2");
Select listbox2 = new Select(driver.findElement(By.id("city")));
listbox2.selectByValue("Chennai");

driver.findElement(By.name("Mobile")).sendKeys("9898765676");

driver.findElement(By.xpath("//div[contains(@style,'block')]//input[@value='Personal Loan']")).click(); 

driver.findElement(By.xpath("//div[contains(@style,'block')]//input[@value='Home Loan']")).click(); 

driver.findElement(By.xpath("//div[contains(@style,'block')]//input[@value='Car Loan']")).click(); 

driver.findElement(By.xpath("//div[contains(@style,'block')]//input[@value='Loan Against Property']")).click(); 

driver.findElement(By.xpath("//div[contains(@style,'block')]//input[@value='Business Loan']")).click();

driver.findElement(By.xpath("//div[contains(@style,'block')]//input[@value='Credit Card']")).click();

driver.findElement(By.name("submit")).click(); 

Upvotes: 2

Related Questions