Selenium WebDriver Java识别表单输入按钮

时间:2015-08-20 18:54:50

标签: java selenium-webdriver automated-tests

我有一个带html的按钮:

driver.findElement(By.);

在我的Java代码中,我有:

if(isset($_POST['submit'])){

$firstname = htmlentities($_POST['firstname'], ENT_QUOTES, 'UTF-8');
$lastname = htmlentities($_POST['lastname'], ENT_QUOTES, 'UTF-8');
$email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');
$emailrepeat = htmlentities($_POST['emailrepeat'], ENT_QUOTES, 'UTF-8');
$password = htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8');
$passwordrepeat = htmlentities($_POST['passwordrepeat'], ENT_QUOTES, 'UTF-8');



if (empty($firstname)) 
{   
    $fnError = "Please Enter Your First Name";
}
if (empty($lastname)) 
{
    $lnError = "Please Enter Your Last Name";
}


$getEmail = $mysqli->prepare('SELECT * FROM users WHERE email=?');
$getEmail->bind_param('s', $email);
$getEmail->execute();
$getEmail->store_result();
$countRows = $getEmail->num_rows;
if ($countRows > 0) 
{
    $emError = "Email Address Already Exists";
    $countRows = 0;
}



else if (empty($email)) 
{
$emError = "Please Enter an Email Address";
}
else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) 
{
$emError = "Invalid Email Address";
}
else if ($email != $emailrepeat)
{
    $emError = "Emails do not match";
}

if (empty($password)) 
{
    $pwError = "Please Enter a Password";
}
else if (strlen($password)<6)
{
    $pwError = "Password must be atleast 6 characters";
}
else if ($password != $passwordrepeat)
{
    $pwError = "Emails do not match";
}

if (filter_var($email, FILTER_VALIDATE_EMAIL)) 
{

    if ($password == $passwordrepeat and !empty($password) and strlen($password)>5)
    {
        $pwhash = password_hash($password, PASSWORD_BCRYPT, array("cost" => 11));

        if($stmt = $mysqli->prepare("INSERT INTO users (first_name, last_name, email, password) VALUES (?, ?, ?, ?)"))
        {
            $stmt->bind_param("ssss", $firstname, $lastname, $email, $pwhash);
            $stmt->execute();
            $stmt->close();
        }


    }
}
}

<form id="addnewuser" action="<?php echo htmlentities($_SERVER['PHP_SELF']);    ?>" method="POST"> 
</form>

如何选择按钮进行点击/提交?

1 个答案:

答案 0 :(得分:1)

我认为这可以做到:

driver.findElement(By.cssSelector("input[type=submit]")).click();