本文整理匯總了Java中com.gargoylesoftware.htmlunit.html.HtmlForm.getInputByValue方法的典型用法代碼示例。如果您正苦於以下問題:Java HtmlForm.getInputByValue方法的具體用法?Java HtmlForm.getInputByValue怎麽用?Java HtmlForm.getInputByValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.gargoylesoftware.htmlunit.html.HtmlForm
的用法示例。
在下文中一共展示了HtmlForm.getInputByValue方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: webFetch
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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();
}
示例2: searchInBaidu
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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());
}
示例3: download
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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();
}
示例4: getNextUrl
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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;
}
示例5: confirmRecoveryEmail
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的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;
}
示例6: testCategoryOperations
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
@Test
public void testCategoryOperations() throws Exception {
logger.info("start insert category");
HtmlPage adminPage = webClient.getPage(base + "views/admin/index.xhtml");
HtmlAnchor button = adminPage.getAnchors().get(2);
HtmlPage page = button.click();
HtmlForm addCategory = page.getFormByName("addCategoryForm");
String categoryToInsert = "ccccc";
addCategory.getInputByName("addCategoryForm:Category").setValueAttribute(categoryToInsert);
HtmlSubmitInput submitButton = addCategory.getInputByName("addCategoryForm:editinline");
page = submitButton.click();
assertTrue("The category is created", page.asText().contains(categoryToInsert));
HtmlAnchor adminPanel = adminPage.getAnchors().get(1);
page = adminPanel.click();
button = page.getAnchors().get(6);
page = button.click();
HtmlForm editCategory = page.getForms().get(4);
String categoryToUpdate = "aaaaaa";
String firstCategory = "Dummy demo category";
editCategory.getInputByValue(categoryToInsert).setValueAttribute(categoryToUpdate);
submitButton = editCategory.getInputByValue(resourceBundle.getString("Update"));
page = submitButton.click();
assertTrue("The category is updated", page.asText().contains(categoryToUpdate));
button = page.getAnchors().get(7);
page = button.click();
assertTrue("The category is arrowed up",
page.asText().indexOf(categoryToUpdate) < page.asText().indexOf(firstCategory));
button = page.getAnchors().get(4);
page = button.click();
assertTrue("The category is arrowed down",
page.asText().indexOf(categoryToUpdate) > page.asText().indexOf(firstCategory));
button = page.getAnchors().get(8);
page = button.click();
HtmlForm deleteCategory = page.getForms().get(1);
submitButton = deleteCategory.getInputByValue(resourceBundle.getString("Cancel"));
page = submitButton.click();
assertTrue("The delete is canceled",
page.asText().contains(firstCategory) && page.asText().contains(categoryToUpdate));
button = page.getAnchors().get(0);
page = button.click();
assertTrue("In the home page there are two categories",
page.asText().contains(firstCategory) && page.asText().contains(categoryToUpdate));
button = page.getAnchors().get(1);
page = button.click();
button = page.getAnchors().get(8);
page = button.click();
deleteCategory = page.getForms().get(1);
submitButton = deleteCategory.getInputByValue(resourceBundle.getString("Confirm"));
page = submitButton.click();
assertTrue("The delete is confirmed", page.asText()
.contains("\"" + categoryToUpdate + "\" " + resourceBundle.getString("Category_deleted_1")));
}
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:53,代碼來源:ApplicationTestCase.java
示例7: printPlayoffScoresheets
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
/**
* Visit the printable brackets for the division specified and print the
* brackets.
*
* @throws IOException
* @throws MalformedURLException
* @throws InterruptedException
* @throws SAXException
*/
private static void printPlayoffScoresheets(final String division)
throws MalformedURLException, IOException, InterruptedException, SAXException {
final WebClient conversation = WebTestUtils.getConversation();
final Page indexResponse = WebTestUtils.loadPage(conversation, new WebRequest(new URL(TestUtils.URL_ROOT
+ "playoff/index.jsp")));
Assert.assertTrue(indexResponse.isHtmlPage());
final HtmlPage indexHtml = (HtmlPage) indexResponse;
// find form named 'printable'
HtmlForm form = indexHtml.getFormByName("printable");
Assert.assertNotNull("printable form not found", form);
final String formSource = WebTestUtils.getPageSource(form.getPage());
LOGGER.debug("Form source: "
+ formSource);
// set division
final HtmlSelect divisionSelect = indexHtml.getHtmlElementById("printable.division");
final HtmlOption divisionOption = divisionSelect.getOptionByValue(division);
divisionSelect.setSelectedAttribute(divisionOption, true);
// click 'Display Brackets'
final HtmlSubmitInput displayBrackets = form.getInputByValue("Display Brackets");
final com.gargoylesoftware.htmlunit.WebRequest displayBracketsRequest = form.getWebRequest(displayBrackets);
final Page displayResponse = WebTestUtils.loadPage(conversation, displayBracketsRequest);
Assert.assertTrue(displayResponse.isHtmlPage());
final HtmlPage displayHtml = (HtmlPage) displayResponse;
// find form named 'printScoreSheets'
form = displayHtml.getFormByName("printScoreSheets");
Assert.assertNotNull("printScoreSheets form not found", form);
final HtmlCheckBoxInput printCheck = form.getInputByName("print1");
printCheck.setChecked(true);
// click 'Print scoresheets'
final HtmlSubmitInput print = form.getInputByValue("Print scoresheets");
final com.gargoylesoftware.htmlunit.WebRequest printRequest = form.getWebRequest(print);
final Page printResponse = WebTestUtils.loadPage(conversation, printRequest);
// check that result is PDF
Assert.assertEquals("application/pdf", printResponse.getWebResponse().getContentType());
}
示例8: testSimple
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
@Test(timeout = 10000)
public void testSimple() throws Exception {
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://" + WEB_SERVER_NAME + ":" + WEB_SERVER_PORT);
assertTrue(page.asText().contains("JMX Domains"));
String domain = "java.lang";
HtmlAnchor anchor = page.getAnchorByText(domain);
assertNotNull(anchor);
page = anchor.click();
assertTrue(page.asText().contains("Beans in domain " + domain));
anchor = page.getAnchorByName("text");
TextPage textPage = anchor.click();
String bean = "type=Memory";
assertTrue(textPage.getContent().contains(domain + ":" + bean));
anchor = page.getAnchorByText(bean);
page = anchor.click();
assertTrue(page.asText().contains("Information about object " + domain + ":" + bean));
anchor = page.getAnchorByName("text");
textPage = anchor.click();
assertTrue(textPage.getContent().contains("Verbose"));
HtmlForm form = page.getFormByName("Verbose");
assertNotNull(form);
HtmlInput input = form.getInputByName("val");
assertEquals("false", input.getValueAttribute());
assertNotNull(input);
input.setValueAttribute("true");
HtmlElement button = (HtmlElement) page.createElement("button");
button.setAttribute("type", "submit");
// append the button to the form to simulate
form.appendChild(button);
// submit the form
page = button.click();
assertTrue(page.asText().contains("Information about object " + domain + ":" + bean));
form = page.getFormByName("Verbose");
assertNotNull(form);
input = form.getInputByName("val");
assertEquals("true", input.getValueAttribute());
String operation = "gc";
form = page.getFormByName(operation);
assertNotNull(form);
input = form.getInputByValue(operation);
page = input.click();
assertTrue(page.asText().contains("Invoking Operation " + operation));
assertTrue(page.asText().contains(operation + " method successfully invoked."));
anchor = page.getAnchorByName("text");
assertNotNull(anchor);
textPage = anchor.click();
assertEquals(operation + " method successfully invoked.\n", textPage.getContent());
}