所以我想添加一个值,以便在页面提交中存在的表单中传递。
WebDriver driver = new HtmlUnitDriver();
driver.get("http://siteWithForm.com");
// Find the text input element by its name
WebElement form = driver.findElement(By.id("reply_form"));
我想在提交之前在表单中添加一个复选框。
<input type="checkbox" tabindex="25" name="self_copy" value="1" id="copy_message">
好像我应该用JavascriptExecutor做一些事情可能吗?
您可以使用jquery并通过Selenium执行它以附加到您想要的标签:)
import org.openqa.selenium.JavascriptExecutor;
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$("#copy_message").wrap('<input id="copy_message" type="checkbox">'"))