Selenium Web驱动程序 - 未单击复选框

时间:2014-12-12 12:42:13

标签: selenium

我尝试点击链接http://www.deal4loans.com/agent.php中的复选框。但它没有被检查.Below是我的代码。要显示chcek框,我们需要从我的选择中选择第二个选项下来

但我注意到,如果编写代码只是为了检查这些复选框而不添加所有其他字段的数据,除了它工作的复选框。但是当我们为Name,mail id,Iam,city,mobile输入数据时您交易的产品将无法使用。

请帮忙

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("vish@gmail.com");

        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);
     }


     }

1 个答案:

答案 0 :(得分:2)

遇到问题!!

2个div,div为id' div0'和div使用' div1',使用'显示属性'从没有'改变阻止'阻止'并且它们具有相同的复选框,具有相同的值'属性,因此它们没有被点击。下面是该Checkbox块的图像:

enter image description here

下面的代码将始终有效,(o'当然显示选项)。我还使用相对xpath修改了代码以保持一致性:

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("vish@gmail.com");

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();