【发布时间】:2014-12-12 12:42:12
【问题描述】:
我试图单击链接http://www.deal4loans.com/agent.php 中的复选框。但它没有被选中。下面是我的代码。要显示 chcek 框,我们需要从“我是”下拉列表中选择第二个选项
但我注意到,如果编写代码只是为了检查这些复选框而不为除复选框之外的所有其他字段添加数据,它可以工作。但是当我们输入名称、邮件 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("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);
}
}
【问题讨论】:
-
你能试试用 ID 代替 Xpath 作为复选框吗?它适用于 ID。
标签: selenium