我使用带有CSS的Firefox IDE检查元素,但是尝试在我的代码中使用相同元素访问元素时不起作用

时间:2019-04-17 07:04:09

标签: java selenium-webdriver

HTML: mysqli_stmt_execute($stmt);

可以使用Firefox IDE选择元素: if (isset($_POST['register-submit'])) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $password = $_POST['password']; $type = $_POST['utype']; $sql = "INSERT INTO `users`(`idroles`, `user_email`, `first_name`, `last_name`, `password`) VALUES((SELECT `idroles` FROM `roles` WHERE `name`= $type), ?, ?, ?, ?)"; $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql)) { header("Location../View/login_register.php"); exit(); } else if (mysqli_stmt_prepare($stmt, $sql)) { $hashpwd = password_hash($password, PASSWORD_DEFAULT); mysqli_stmt_bind_param($stmt, "ssss", $firstname, $lastname, $email, $hashpwd); mysqli_stmt_execute($stmt); header("Location:../View/login_register.php?success"); exit(); } }

我需要将出现Firefox IDE的CSS转换为我的代码中可以使用的路径

<input name="txtAnswer" class="box1" id="txtAnswer" type="text" maxlength="20">

1 个答案:

答案 0 :(得分:0)

尝试使用 JavascriptExecutor

JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.name("txtAnswer"));
js.executeScript("arguments[0].setAttribute('style', 'colour:green')", element);

最好通过唯一ID而不是名称来使用findElement。

此处有更多详细信息:How can i set new style of element using selenium web-driver