本文整理汇总了Java中com.gargoylesoftware.htmlunit.html.HtmlPage.getElementById方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlPage.getElementById方法的具体用法?Java HtmlPage.getElementById怎么用?Java HtmlPage.getElementById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gargoylesoftware.htmlunit.html.HtmlPage
的用法示例。
在下文中一共展示了HtmlPage.getElementById方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allowAccess
import com.gargoylesoftware.htmlunit.html.HtmlPage; //导入方法依赖的package包/类
private HtmlPage allowAccess(WebClient webClient, HtmlPage allowAccessPage) throws IOException {
HtmlButton allowAccessButton = (HtmlButton) allowAccessPage.getElementById("submit_approve_access");
if (allowAccessButton == null) {
throw new RuntimeException("Cannot find allow access button in html page :\n" + allowAccessPage.asXml());
}
webClient.waitForBackgroundJavaScriptStartingBefore(WAIT_DELAY_MS);
// allowAccessButton.click() does not work because
// allowAccessButton.isVisible() is false
// for some reason (click() was working with htmlunit 2.23)
HtmlPage tokenPage = clickButtonIgnoringVisibility(allowAccessButton);
return tokenPage;
}
示例2: roomBooking
import com.gargoylesoftware.htmlunit.html.HtmlPage; //导入方法依赖的package包/类
public void roomBooking( User user, Meeting meeting ) throws Exception
{
List< String > errorMessages = new ArrayList< String >();
HtmlPage page = navigateToPage( user, BOOKING, true );
logger.debug( "Page loaded" );
HtmlForm form = page.getForms().get( 0 );
HtmlButton button = form.getFirstByXPath( "//*[@id=\"Submit\"]" );
HtmlSelect select = (HtmlSelect)page.getElementById( "ConferenceRooms" );
HtmlOption option = select.getOptionByText( meeting.getRoom() );
select.setSelectedAttribute( option, true );
Date date = meeting.getDate();
if( date != null )
{
HtmlTextInput startDate = form.getFirstByXPath( ".//*[@id='StartDate']" );
DateFormat formatter = new SimpleDateFormat( "MM/dd/yyyy" );
startDate.setAttribute( "value", formatter.format( date ) );
}
HtmlInput inputStartTime = form.getInputByName( "StartTime" );
inputStartTime.setValueAttribute( meeting.getFromTime() );
HtmlInput inputEndTime = form.getInputByName( "EndTime" );
inputEndTime.setValueAttribute( meeting.getToTime() );
HtmlInput inputReason = form.getInputByName( "Title" );
inputReason.type( meeting.getReason() );
List< String > attendeesList = meeting.getAttendees();
if( attendeesList != null && attendeesList.size() > 0 )
{
HtmlSelect attendees = (HtmlSelect)page.getElementById( "AttendeesIds" );
for( String participant : attendeesList )
{
attendees.getOptionByText( participant ).setSelected( true );
}
}
logger.debug( "Page filled, clicking button" );
HtmlPage nextPage = button.click();
String pageUrl = new StringBuilder( "http://" ).append( WEBSITE ).append( SHOW_MY_BOOKINGS ).toString();
if( !nextPage.getBaseURI().equals( pageUrl ) )
{
errorMessages.add( "Room already booked" );
logger.error( errorMessages );
throw new InvalidInputException( errorMessages );
}
// Error check
DomNodeList< DomElement > list = page.getElementsByTagName( "span" );
for( DomElement domElement : list )
{
if( domElement.getAttribute( "class" ).contains( "field-validation-error" ) )
{
errorMessages.add( domElement.getTextContent() );
}
}
if( errorMessages.size() > 0 )
{
logger.error( errorMessages );
throw new InvalidInputException( errorMessages );
}
}
示例3: testGetToken
import com.gargoylesoftware.htmlunit.html.HtmlPage; //导入方法依赖的package包/类
public void testGetToken() throws FailingHttpStatusCodeException, IOException {
WebClient wc = weiWS.getInstance();
WebRequest wr = new WebRequest(new URL("https://mp.weixin.qq.com/cgi-bin/login"), HttpMethod.POST);
wr.getAdditionalHeaders().put("Accept", "*/*");
wr.getAdditionalHeaders().put("Accept-Encoding", "gzip, deflate, br");
wr.getAdditionalHeaders().put("Accept-Language", "en-US,en;q=0.5");
wr.getAdditionalHeaders().put("Connection", "keep-alive");
// wr.getAdditionalHeaders().put("Content-Length", "86");
wr.getAdditionalHeaders().put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
wr.getAdditionalHeaders().put("Host", "mp.weixin.qq.com");
wr.getAdditionalHeaders().put("Referer", "https://mp.weixin.qq.com/");
wr.getAdditionalHeaders().put("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0");
wr.getAdditionalHeaders().put("X-Requested-With", "XMLHttpRequest");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("f", "json"));
params.add(new NameValuePair("imgcode", ""));
//3BCEBC34A480F472E27372F9DE2D5592
params.add(new NameValuePair("pwd", "3bcebc34a480f472e27372f9de2d5592"));
params.add(new NameValuePair("username", "[email protected]"));
wr.setRequestParameters(params);
Page page = wc.getPage(wr);
String response = page.getWebResponse().getContentAsString();
System.out.println(response);
Set<Cookie> cookies = weiWS.getInstance().getCookieManager().getCookies();
for (Cookie cookie : cookies) {
System.out.println(cookie.toString());
}
Gson gson = new Gson();
RespWithTokenJSON jsonObj = gson.fromJson(response, RespWithTokenJSON.class);
String homePath = jsonObj.getRedirect_url();
HtmlPage homePage = wc.getPage("https://mp.weixin.qq.com/" + homePath);
HtmlAnchor logout = (HtmlAnchor) homePage.getElementById("logout");
System.out.println(logout);
HtmlPage loginPage = wc.getPage("https://mp.weixin.qq.com");
System.out.println(loginPage.getUrl());
}
示例4: setInput
import com.gargoylesoftware.htmlunit.html.HtmlPage; //导入方法依赖的package包/类
protected void setInput(HtmlPage page, String uid, String password) {
HtmlElement ue = (HtmlElement) page.getElementById("u");
ue.setAttribute("value", uid);
HtmlElement pe = (HtmlElement) page.getElementById("p");
pe.setAttribute("value", password);
}
示例5: isSelectChallengePage
import com.gargoylesoftware.htmlunit.html.HtmlPage; //导入方法依赖的package包/类
private boolean isSelectChallengePage(HtmlPage htmlPage) {
return htmlPage.getElementById("challengePickerList") != null;
}
示例6: main
import com.gargoylesoftware.htmlunit.html.HtmlPage; //导入方法依赖的package包/类
public static void main(String[] args)throws Exception {
WebClient webClient = HtmlUnitUtil.create();
HtmlPage htmlPage = webClient.getPage("http://s.click.taobao.com/8NF1HQx");
Thread.sleep(1000);
/*System.out.println(htmlPage.getUrl());
htmlPage = webClient.getPage("http://s.click.taobao.com/t_js?tu=http%3A%2F%2Fs.click.taobao.com%2Ft%3Fe%3Dm%253D2%2526s%253Db1p5j7LwD1UcQipKwQzePOeEDrYVVa64K7Vc7tFgwiHjf2vlNIV67jjoSPUdWv%252F4VNjKoH%252FaCQPRGePCFkAxw1IwogiijGrXXM5lrk7Nf8aaImqn1I7ptgIGMGGjWrSklrfKbc84rlduVmJJG43TQWl81IfQPxUgomfkDJRs%252BhU%253D%26pvid%3D10_27.151.93.69_5766_1477199325118%26ref%3D%26et%3DX361fgWzYAU%252BFl40OhTkQ87gYurDEZH1");
Thread.sleep(1000);*/
/*
ScriptResult scriptResult = htmlPage.executeJavaScript("bol();");
System.out.println(scriptResult.toString());
Thread.sleep(1000);*/
//System.out.println(htmlPage.getUrl());
//System.out.println(htmlPage.getPage().asXml());
String url = htmlPage.getUrl().toString();
System.out.println(url);
HtmlElement domElement = (HtmlElement) htmlPage.getElementById("exe");
htmlPage = domElement.click();
url = htmlPage.getUrl().toString();
System.out.println(url);
htmlPage = webClient.getPage(url);
url = htmlPage.getUrl().toString();
System.out.println(url);
url = HttpClientDemo302.getRedirectInfo2(url);
System.out.println(url);
}