使用java自动使用selenium进行Facebook注册过程,但无法选择单选按钮

时间:2016-08-15 13:18:41

标签: java selenium-webdriver

我无法点击Facebook登录页面上的“创建帐户”按钮。我们无法将单选按钮存储到List中,因为没有单独的web元素作为Gender。

header('Content-Type: application/force-download');
header('Content-Disposition: attachment;filename="BASIC_Data.xls"');
header('Cache-Control: max-age=0');

2 个答案:

答案 0 :(得分:0)

尝试使用此代码,它对我有用:

driver.findElement(By.cssSelector("[id=u_0_j]")).click();
driver.findElement(By.cssSelector("[id=u_0_n]")).click();

答案 1 :(得分:0)

我们只能选择一个单选按钮

公共类DropDownDemo {

public static void main(String[] args) throws InterruptedException {
    // TODO Auto-generated method stub

    System.setProperty("webdriver.chrome.driver", "C:\\sruthi-selenium\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    driver.get("https://www.facebook.com/");
    driver.manage().window().maximize();

    //text fields
    driver.findElement(By.id("u_0_j")).sendKeys("sruthi");
    driver.findElement(By.name("lastname")).sendKeys("karpuram");
    driver.findElement(By.name("reg_email__")).sendKeys("84521636866");
    driver.findElement(By.name("reg_passwd__")).sendKeys("il9HNJ1234");

    //static drop down
    Select s = new Select(driver.findElement(By.id("day")));
    Thread.sleep(1000);
    s.selectByVisibleText("12");

    Select s1 = new Select(driver.findElement(By.id("month")));
    Thread.sleep(1000);
    s1.selectByValue("5");

    Select s2 = new Select(driver.findElement(By.id("year")));
    Thread.sleep(1000);
    s2.selectByValue("1993");
    //radio button
        driver.findElement(By.xpath("//input[@value='2']")).click();//for selecting male

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

    driver.close();



}

}