本文整理汇总了Java中com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.click方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlSubmitInput.click方法的具体用法?Java HtmlSubmitInput.click怎么用?Java HtmlSubmitInput.click使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gargoylesoftware.htmlunit.html.HtmlSubmitInput
的用法示例。
在下文中一共展示了HtmlSubmitInput.click方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFormOk
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
/**
* Retrieve a form and submit it making sure the CSRF hidden field is present
*
* @throws Exception an error occurs or validation fails.
*/
@Test
public void testFormOk() throws Exception {
HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");
HtmlForm form = (HtmlForm) page1.getDocumentElement().getHtmlElementsByTagName("form").get(0);
// Check hidden input field
HtmlElement input = form.getHtmlElementsByTagName("input").get(1);
assertTrue(input.getAttribute("type").equals("hidden"));
assertTrue(input.getAttribute("name").equals(CSRF_PARAM));
assertTrue(input.hasAttribute("value")); // token
// Submit form
HtmlSubmitInput button = (HtmlSubmitInput) form.getHtmlElementsByTagName("input").get(0);
HtmlPage page2 = button.click();
Iterator<HtmlElement> it = page2.getDocumentElement().getHtmlElementsByTagName("h1").iterator();
assertTrue(it.next().asText().contains("CSRF Protection OK"));
}
示例2: testFormFail
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
/**
* Retrieves a form, removes CSRF hidden field and attempts to submit. Should
* result in a 403 error.
*
* @throws Exception an error occurs or validation fails.
*/
@Test
public void testFormFail() throws Exception {
HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");
HtmlForm form = (HtmlForm) page1.getDocumentElement().getHtmlElementsByTagName("form").get(0);
// Remove hidden input field to cause a CSRF validation failure
HtmlElement input = form.getHtmlElementsByTagName("input").get(1);
form.removeChild(input);
// Submit form - should fail
HtmlSubmitInput button = (HtmlSubmitInput) form.getHtmlElementsByTagName("input").get(0);
try {
button.click();
fail("CSRF validation should have failed!");
} catch (FailingHttpStatusCodeException e) {
// falls through
}
}
示例3: getCallbackUrl
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
@Override
protected String getCallbackUrl(HtmlPage authorizationPage) throws Exception {
HtmlInlineFrame frame = (HtmlInlineFrame) authorizationPage.getElementById("ptlogin_iframe");
// log.info("------------------------###\n{}------------------------===\n", authorizationPage.asXml());
HtmlPage loginPage = (HtmlPage) frame.getEnclosedPage();
log.info("------------------------###\n{}------------------------===\n", loginPage.getUrl().toString());
HtmlAnchor passwordLogin = (HtmlAnchor) loginPage.getElementById("switcher_plogin");
passwordLogin.click();
HtmlForm loginForm = loginPage.getFormByName("loginform");
loginForm.getInputByName("u").setValueAttribute(USER_QQ);
loginForm.getInputByName("p").setValueAttribute(USER_PASSWORD);
HtmlSubmitInput button = (HtmlSubmitInput) loginPage.getElementById("login_button");
HtmlPage page2 = button.click();
page2 = button.click();
log.info(
"------------------------###\n callbackUrl : {}------------------------===\n{}[email protected]@@@\n",
page2.getUrl().toString(), page2.asXml());
return page2.getUrl().toString();
}
示例4: loadPage
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
public void loadPage() {
try {
// Store cookies
cookieManager = webClient.getCookieManager();
page = webClient.getPage(URL);
HtmlForm form = page.getFormByName("processLogonForm");
HtmlSubmitInput button = form.getInputByName("Login");
HtmlTextInput user = form.getInputByName("userName");
HtmlPasswordInput pass = form.getInputByName("password");
user.setValueAttribute(username);
pass.setValueAttribute(password);
page = button.click();
if (page.asXml().contains("* Please try again.")) {
loginSuc = false;
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: checkAdOnline
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
public static boolean checkAdOnline(String adId)
{
try
{
WebClient client = Client.get();
String urlDelete = LinkFactory.AD_DELETE_LINK_1 + adId;
final HtmlPage deletePage1 = client.getPage(urlDelete);
HtmlRadioButtonInput deleteRadioButton = (HtmlRadioButtonInput) deletePage1.getElementById("cmd_delete");
deleteRadioButton.setChecked(true);
HtmlSubmitInput continueButton = deletePage1.getElementByName("continue");
final HtmlPage deletePage2 = continueButton.click();
if (deletePage2.asXml().contains("dans quelques minutes") && deletePage2.asXml().contains("Vous ne pouvez pas"))
{
return false;
}
}
catch (Exception e)
{
Logger.traceERROR(e);
}
return true;
}
示例6: webFetch
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
public void webFetch(String userInput,String pwdInput) throws Exception{
final WebClient webClient=new WebClient();
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
final HtmlPage page=webClient.getPage("https://account.xiaomi.com/pass/serviceLogin");
//��ȡ��
final HtmlForm form=(HtmlForm)page.getElementById("loginForm");
//��ȡ�ύ�ť
final HtmlSubmitInput button=form.getInputByValue("��¼");
HtmlTextInput userId=form.getInputByName("user");
HtmlPasswordInput pwd=form.getInputByName("pwd");
userId.setText(userInput);
pwd.setText(pwdInput);
final HtmlPage next=button.click();
System.out.println(next.asText());
webClient.closeAllWindows();
}
示例7: testGetWithCorrectCredentials
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
@Test
public void testGetWithCorrectCredentials() throws Exception {
logger.info("start get request with correct credentials");
loginForm.getInputByName("j_username").setValueAttribute("u1");
loginForm.getInputByName("j_password").setValueAttribute("p1");
HtmlSubmitInput submitButton = loginForm.getInputByName("submitButton");
HtmlPage page2 = submitButton.click();
assertEquals("Form-based Security - Success", page2.getTitleText());
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:10,代码来源:SecureFormTestCase.java
示例8: testGetWithIncorrectCredentials
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
@Test
public void testGetWithIncorrectCredentials() throws Exception {
logger.info("start get request with incorrect credentials");
loginForm.getInputByName("j_username").setValueAttribute("random");
loginForm.getInputByName("j_password").setValueAttribute("random");
HtmlSubmitInput submitButton = loginForm.getInputByName("submitButton");
HtmlPage page2 = submitButton.click();
assertEquals("Form-Based Login Error Page", page2.getTitleText());
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:10,代码来源:SecureFormTestCase.java
示例9: post
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
private String post(){
String postedUrl = null;
String domain = Globals.paths.RemoteAdminUrl.substring(0,Globals.paths.RemoteAdminUrl.lastIndexOf("wp-admin")-1)+"/";
webPageManipulation = new WebPageManipulation(connection.getStartPage());
DomElement titleElement = webPageManipulation.getElementById("title");
HtmlTextArea contentElement =(HtmlTextArea) webPageManipulation.getElementById("content");
HtmlSubmitInput publishButton = (HtmlSubmitInput)webPageManipulation.getElementById("publish");
webPageManipulation.setElement(titleElement, InputObject.getTitle());
contentElement.setText(AdCode+"\n"+EmbedCode.replaceFirst("#", InputObject.getVideoUrl().replace("watch?v=", "/embed/"))+
"\n"+EmbedCode.replaceFirst("#", InputObject.getVideoUrl().replace("watch?v=", "/embed/"))+"\n"+InputObject.getDescription());
try {
HtmlPage nxt = publishButton.click();
webPageManipulation.setPage(nxt);
DomElement url_posted = webPageManipulation.getElementById("editable-post-name-full");
String postUrl = domain+url_posted.getTextContent();
JOptionPane.showMessageDialog(null, postUrl);
StringSelection selection = new StringSelection(postUrl);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
} catch (IOException e) {
//Get Default Dialog used for exceptions, & add exception
//Show Dialog
}
return postedUrl;
}
示例10: logIn
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
private void logIn()throws IOException{
final HtmlPage page = browser.getPage("http://codeforces.com/enter");
final HtmlTextInput handle = (HtmlTextInput)page.getByXPath("//input[@id='handle']").get(0);
final HtmlPasswordInput pass = (HtmlPasswordInput)page.getByXPath("//input[@id='password']").get(0);
final HtmlSubmitInput btn = (HtmlSubmitInput)page.getByXPath("//input[@class='submit']").get(0);
// Change the value of the text fields
handle.setValueAttribute(user_name);
pass.setValueAttribute(pass_word);
// Now submit the form by clicking the button
btn.click();
}
示例11: searchInBaidu
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
public void searchInBaidu() throws Exception {
HtmlPage page = webClient.getPage("https://www.baidu.com/");
HtmlForm form = page.getFormByName("f");
HtmlTextInput input = form.getInputByName("wd");
HtmlSubmitInput button = form.getInputByValue("百度一下");
input.setValueAttribute("无锡");
HtmlPage nextPage = button.click();
//System.out.println(nextPage.asXml());
// hit next page
HtmlAnchor next = null;
List list = nextPage.getByXPath("//a");
for(Object obj : list) {
if(obj instanceof HtmlAnchor) {
HtmlAnchor ha = (HtmlAnchor)obj;
//System.out.println(ha.getTextContent());
if(ha.getTextContent().indexOf("百度百科") != -1) {
next = ha;
break;
}
}
}
System.out.println(next.asXml());
System.out.println("--------------------------");
HtmlPage p = next.click();
System.out.println(p.asXml());
}
示例12: download
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
/**
* return the html of url
* @param url : form data
* @param inputs : input name -> input value
* @return
*/
public String download(URL url, Map<String, String> inputs) {
HtmlSubmitInput button = null;
HtmlPage nextPage = null;
try {
HtmlPage page = webClient.getPage(url.getURLValue());
for(Map.Entry<String, String> input : inputs.entrySet()) {
String form_name = input.getKey().split("\\.")[0];
String input_name = input.getKey().split("\\.")[1];
HtmlForm form = page.getFormByName(form_name);
if(input_name.equals("button")) {
button = form.getInputByValue(input.getValue());
}
else {
HtmlTextInput text_input = form.getInputByName(input_name);
text_input.setValueAttribute(input.getValue());
}
}
nextPage = button.click();
} catch(IOException ioe) {
ioe.printStackTrace();
}
return nextPage.asXml();
}
示例13: getNextUrl
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
/**
* 通过htmlunit来获得一些搜狗的网址。
* @param key
* @return
* @throws Exception
*/
public String getNextUrl(String key){
String page = new String();
try {
WebClient webClient = new WebClient();
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
//去拿网页
HtmlPage htmlPage = webClient.getPage("http://pic.sogou.com/");
//得到表单
HtmlForm form = htmlPage.getFormByName("searchForm");
//得到提交按钮
HtmlSubmitInput button = form.getInputByValue("搜狗搜索");
//得到输入框
HtmlTextInput textField = form.getInputByName("query");
//输入内容
textField.setValueAttribute(key);
//点一下按钮
HtmlPage nextPage = button.click();
String str = nextPage.toString();
page = cutString(str);
webClient.close();
} catch (Exception e) {
// TODO: handle exception
} finally{
}
System.out.println();
return page;
}
示例14: confirmRecoveryEmail
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
private HtmlPage confirmRecoveryEmail(WebClient webClient, HtmlPage htmlPage) throws IOException {
List<HtmlForm> forms = htmlPage.getForms();
HtmlForm challengeForm = forms.stream().filter(
form -> "challenge".equals(form.getId()) && "/signin/challenge/kpe/2".equals(form.getActionAttribute()))
.findFirst().get();
HtmlInput htmlInput = challengeForm.getInputByName("email");
htmlInput.setValueAttribute(recoveryEmail.get());
HtmlSubmitInput signInButton = (HtmlSubmitInput) challengeForm.getInputByValue("Done");
HtmlPage nextPage = signInButton.click();
webClient.waitForBackgroundJavaScriptStartingBefore(WAIT_DELAY_MS);
return nextPage;
}
示例15: setup
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; //导入方法依赖的package包/类
@Before
public void setup() throws IOException {
String hostProperty = System.getProperty("jonas.host");
if (hostProperty != null) {
this.config.setHost(hostProperty);
}
String portProperty = System.getProperty("webcontainer.port");
if (portProperty != null) {
this.config.setPort(Long.parseLong(portProperty));
}
this.urlString = "http://" + config.getHost() + ":" + config.getPort()+ "/paas-portal/";
log.debug("setUp urlString=" + urlString);
final HtmlPage page = webClient.getPage(urlString);
WebAssert.assertTitleEquals(page, "GASSI - El Paaso login");
final HtmlForm form = page.getFormByName("loginform");
final HtmlSubmitInput button = form.getInputByName("submit");
final HtmlTextInput login = form.getInputByName("login");
final HtmlPasswordInput password = form.getInputByName("password");
login.setText("tescalle");
password.setText("tescalle");
home = button.click();
// TODO : uncomment when dbaas deletion will be working on env deletion
// home = webClient.getPage("http://" + host + ":" + port + "/paas-portal/app/scalability/setup");
}