2014-12-12 5 views
0

링크 http://www.deal4loans.com/agent.php의 확인란을 클릭하려고했습니다.하지만 체크되지 않습니다. 아래 코드는 내 코드입니다. chcek 박스를 표시하려면 2 번째 옵션을 선택해야합니다 에서 내가 내려 왔어요Selenium web driver - 체크 박스가 클릭되지 않음

그러나 코드는 확인란을 제외한 다른 모든 필드에 대한 데이터를 추가하지 않고 이러한 확인란을 확인하기 위해 작성된 경우에만 작동합니다.하지만 우리가 이름, 메일 ID에 대한 데이터를 입력하면 , Iam, 도시, 모바일, 거래하는 제품은 작동하지 않습니다.

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


    } 
+0

체크 박스 대신 Xpath를 입력 할 수 있습니까? 그것은 ID와 함께 작동합니다. –

답변

2

문제가있어 도와주세요!

가 '블록'을 '없음'에서 변경 "표시 속성 '인 2 div가'div1 '와 ID'Div0을 '및 DIV와 DIV는, 그리고 그들은 동일한'값 '속성과 동일한 체크 박스를 및 따라서 클릭하지 못했습니다. 코드 아래

enter image description here

이 항상 작동합니다 (옵션이 표시됩니다 o'course) : 아래는 그 체크 박스 블록에 대한 이미지입니다. 일관성을 위해 상대 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("[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(); 
+0

그게 작동 Subh. –

+0

@RupeshShinde : 이것은 까다 롭습니다. :) – Subh

+0

1upvote from me..subh. –

관련 문제