Results 1 to 2 of 2
  1. #1
    ahmad_javadi is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default use of pressAccessKey in htmlunit

    hello
    i need to use of " public HtmlElement pressAccessKey(char accessKey)
    throws IOException" for press desired key on the webpage that read by function "HtmlPage getPage()" in the htmlunit library
    so for test an learn this function i use this code but not work
    "
    form.getInputByName("data[title]").click();
    page.setFocusedElement(form.getInputByName("data[title]")) page.pressAccessKey('a');
    "
    while this code work correct
    "
    form.getInputByName("data[title]").setValueAttribute(Title);
    "
    so i need to example for preesAccessKey function that work correct
    so help me in this case.
    thanks

  2. #2
    FacaNaCaveira is offline Member
    Join Date
    Jul 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    8
    Rep Power
    0

    Lightbulb

    Good Morning ahmad_javadi,

    I search some documents in internet and found references and a exemple of implemention. Search in these pages for pressAccessKey com.gargoylesoftware.htmlunit.html.HtmlPage - Java Examples
    You can see other superficial references in these websites Uses of Class com.gargoylesoftware.htmlunit.html.HtmlElement (HtmlUnit 2.7 API) or HtmlPage (HtmlUnit 2.1 API)

    This is the example:
    Java Code:
    1155:    /**
    1156:     * Simulate pressing an access key.  This may change the focus, may click buttons and may invoke
    1157:     * javascript.
    1158:     *
    1159:     * @param accessKey The key that will be pressed.
    1160:     * @return The element that has the focus after pressing this access key or null if no element
    1161:     * has the focus.
    1162:     * @throws IOException If an io error occurs during the processing of this access key.  This
    1163:     * would only happen if the access key triggered a button which in turn caused a page load.
    1164:     */
    1165:...	      public HtmlElement pressAccessKey( final char accessKey ) throws IOException {
    1166:        final HtmlElement element = getHtmlElementByAccessKey(accessKey);
    1167:        final WebClient webClient = getWebClient();
    1168:...	          if( element != null ) {
    1169:...	              if( element instanceof FocusableElement ) {
    1170:                ((FocusableElement) element).focus();
    1171:            }
    1172:
    1173:            final Page newPage;
    1174:...	              if( element instanceof HtmlAnchor ) {
    1175:                newPage = ((HtmlAnchor)element).click();
    1176:            }
    1177:...	              else if( element instanceof HtmlArea ) {
    1178:                newPage = ((HtmlArea)element).click();
    1179:            }
    1180:...	              else if( element instanceof HtmlButton ) {
    1181:                newPage = ((HtmlButton)element).click();
    1182:            }
    1183:...	              else if( element instanceof HtmlInput ) {
    1184:                newPage = ((HtmlInput)element).click();
    1185:            }
    1186:...	              else if( element instanceof HtmlLabel ) {
    1187:                newPage = ((HtmlLabel)element).click();
    1188:            }
    1189:...	              else if( element instanceof HtmlLegend ) {
    1190:                newPage = ((HtmlLegend)element).click();
    1191:            }
    1192:...	              else if( element instanceof HtmlTextArea ) {
    1193:                newPage = ((HtmlTextArea)element).click();
    1194:            }
    1195:...	              else {
    1196:                newPage = this;
    1197:            }
    1198:
    1199:...	              if( newPage != this && webClient.getElementWithFocus() == element ) {
    1200:                // The page was reloaded therefore no element on this page will have the focus.
    1201:                webClient.getElementWithFocus().blur();
    1202:            }
    1203:        }
    1204:
    1205:        return webClient.getElementWithFocus();
    1206:    }
    Abração:cool:
    Max

Similar Threads

  1. i cannot give this page with htmlunit
    By ansar313 in forum New To Java
    Replies: 11
    Last Post: 05-20-2011, 08:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •