⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlparser.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    {        HTMLCollection links = document.getLinks();                for(int i = 0; i < links.getLength(); i++)        {            if (name.equals( ((HTMLElement) links.item(i)).                              getAttribute("name") ))            {                if ( org.apache.html.dom.HTMLAnchorElementImpl.class                      == links.item(i).getClass())                return new WebLink((HTMLAnchorElement)links.item(i), i + 1);                if ( org.apache.html.dom.HTMLAreaElementImpl.class                      == links.item(i).getClass())                return new WebLink((HTMLAreaElement)links.item(i), i + 1);            }        }                throw new InvalidElementIDException (name, "Link " + name);    }            /*****************************************************************************//*                                                                           *//* Method: getLinkByIndex                                                    *//* Description: get the WebLink at index.                                    *//* Parameters: index - the index of the link                                 *//* Returns: html link                                                        *//*                                                                           *//*****************************************************************************/            public WebLink getLinkByIndex(int index) throws InvalidElementIDException    {        HTMLCollection links = document.getLinks();                index --;                if ( index < links.getLength() && index > -1 )        {            if ( org.apache.html.dom.HTMLAnchorElementImpl.class                  == links.item(index).getClass())            return new WebLink((HTMLAnchorElement)links.item(index), index + 1);            if ( org.apache.html.dom.HTMLAreaElementImpl.class                  == links.item(index).getClass())            return new WebLink((HTMLAreaElement)links.item(index), index + 1);        }                throw new InvalidElementIDException (new Integer(index + 1),                                               "Link index " + (index + 1));    }    /*****************************************************************************//*                                                                           *//* Method: getFormByID                                                       *//* Description: get the WebForm identified by with id attribute id.          *//* Parameters: id - id attribute to identify the form by                     *//* Returns: html form                                                        *//*                                                                           *//*****************************************************************************/            public WebForm getFormByID(String id) throws InvalidElementIDException    {        HTMLCollection forms = document.getForms();                for(int i = 0; i < forms.getLength(); i++)        {            if (id.equals( ((HTMLElement) forms.item(i)).getId() ))                return new WebForm((HTMLFormElement)forms.item(i), i + 1);        }                throw new InvalidElementIDException (id, "Form " + id);            }        /*****************************************************************************//*                                                                           *//* Method: getFormByName                                                     *//* Description: get the WebForm identified by with name attribute name.      *//* Parameters: name - name attribute to identify the form by                 *//* Returns: html form                                                        *//*                                                                           *//*****************************************************************************/            public WebForm getFormByName(String name) throws InvalidElementIDException    {        HTMLCollection forms = document.getForms();                for(int i = 0; i < forms.getLength(); i++)        {            if (name.equals( ((HTMLFormElement) forms.item(i)).getName() ))                return new WebForm((HTMLFormElement)forms.item(i), i + 1);        }                throw new InvalidElementIDException (name, "Form " + name);    }            /*****************************************************************************//*                                                                           *//* Method: getFormByIndex                                                    *//* Description: get the WebForm identified by with name attribute name.      *//* Parameters: index - the index of the form                                 *//* Returns: html form                                                        *//*                                                                           *//*****************************************************************************/            public WebForm getFormByIndex(int index) throws InvalidElementIDException    {        HTMLCollection forms = document.getForms();                index --;                if ( index < forms.getLength() && index > -1 )            return new WebForm((HTMLFormElement)forms.item(index), index + 1);                throw new InvalidElementIDException (new Integer(index + 1),                                               "Form index " + (index + 1));    }            /*****************************************************************************//*                                                                           *//* Method: listForms                                                         *//* Description: get a list of WebForms in the page.                          *//* Parameters: none                                                          *//* Returns: a list of form details                                           *//*                                                                           *//*****************************************************************************/            public HashMap[] listForms()    {        HTMLCollection forms = document.getForms();                HashMap [] list = new HashMap[forms.getLength()];                    for (int i = 0; i < list.length; i++)            list[i] = (new WebForm((HTMLFormElement)forms.item(i), i + 1)).                       getSummary();                    return list;    }            /*****************************************************************************//*                                                                           *//* Method: listLinks                                                         *//* Description: get a list of WebLinks in the page.                          *//* Parameters: none                                                          *//* Returns: a list of link details                                           *//*                                                                           *//*****************************************************************************/            public HashMap[] listLinks()    {        HTMLCollection links = document.getLinks();                HashMap [] list = new HashMap[links.getLength()];                    for (int i = 0; i < list.length; i++)            if ( org.apache.html.dom.HTMLAnchorElementImpl.class                  == links.item(i).getClass())                            list[i] = (new WebLink((HTMLAnchorElement)links.item(i), i + 1)).                           getSummary();                        else if ( org.apache.html.dom.HTMLAreaElementImpl.class                        == links.item(i).getClass())                            list[i] = (new WebLink((HTMLAreaElement)links.item(i), i + 1)).                          getSummary();                    return list;    }            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -