public class DocumentParser
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ASSIGN_SEPARATOR |
static java.lang.String |
BOUDNS_SEPARATOR |
java.util.HashMap<java.lang.String,org.dom4j.Document> |
documents
documents is a map-cache to contain dom4j-document as value and URL as key.
|
static java.lang.String |
RECOGNITION_LEVEL_SEPARATOR |
(package private) com.thoughtworks.selenium.Selenium |
selenium |
int |
timeconsume1 |
int |
timeconsume2 |
int |
timeconsume3 |
java.lang.String |
url |
(package private) SeleniumGUIUtilities |
util |
static java.lang.String |
XPATH_ALL_ELEMENTS |
static java.lang.String |
XPATH_ALL_LEVEL_PREFIX |
static java.lang.String |
XPATH_ATTRIBUTES |
Constructor and Description |
---|
DocumentParser(com.thoughtworks.selenium.Selenium selenium,
SeleniumGUIUtilities util) |
DocumentParser(java.lang.String url) |
Modifier and Type | Method and Description |
---|---|
boolean |
checkAttributes(org.dom4j.Node node,
java.lang.String[][] attrcheck,
boolean matchPartial) |
java.lang.String[] |
getAllElements() |
void |
getAllElementsR(org.dom4j.Document doc,
java.lang.String prefix,
int top,
int left,
java.lang.String docURL,
java.util.List<java.lang.String> elementsXpathList)
Note: This is a recursive method, for each frame in this document, this method will be called.
|
java.util.List<java.lang.String> |
getAllXPath(org.dom4j.Document doc,
java.lang.String[] tags) |
java.lang.String |
getAttribute(org.dom4j.Document doc,
java.lang.String xpath,
java.lang.String attribute)
Purpose: Get the value of an attribute
|
java.lang.String |
getAttribute(org.dom4j.Node node,
java.lang.String attribute)
Purpose: Get the value of an attribute
|
java.lang.String |
getAttribute(java.lang.String url,
java.lang.String xpath,
java.lang.String attribute)
Purpose: Get the value of an attribute
|
java.util.HashMap |
getAttributes(org.dom4j.Document doc,
java.lang.String xpath)
Purpose: Get all properties of an element on html page.
|
java.util.HashMap |
getAttributes(org.dom4j.Node node)
Purpose: Get all properties of an element on html page.
|
java.util.HashMap |
getAttributes(java.lang.String url,
java.lang.String xpath)
Purpose: Get all properties of an element on html page.
|
java.lang.String |
getBoundsSeparator() |
java.lang.String |
getBrowserClientScreenPosition(com.thoughtworks.selenium.Selenium selenium) |
java.lang.String |
getClientScrollInfo(com.thoughtworks.selenium.Selenium selenium) |
org.dom4j.Document |
getDocument(java.lang.String url,
boolean changeMainPageURL) |
org.dom4j.Element |
getElementFromXpath(org.dom4j.Document document,
java.lang.String xpath) |
java.util.List |
getElementsMatchingTags(org.dom4j.Document document,
java.lang.String[] tags) |
java.lang.String |
getEncodingName(java.io.InputStream ins)
Note: To detect the encoding of the input-stream
|
int |
getFrameIndex(org.dom4j.Document document,
java.lang.String xpath) |
int |
getFrameLeft(org.dom4j.Node frameNode) |
java.lang.String |
getFrameSrcURL(org.dom4j.Document document,
java.lang.String xpath,
java.lang.String parentURL) |
java.lang.String |
getFrameSrcURL(org.dom4j.Node frameNode,
java.lang.String parentURL) |
int |
getFrameTop(org.dom4j.Node frameNode) |
int |
getIndex(org.dom4j.Document document,
org.dom4j.Element element) |
java.lang.String |
getInnerHtml(java.lang.String content,
java.lang.String tag)
Purpose: get the innerHTML from page content
Note: The tag must be the beginning and ending tag of the content |
java.lang.String |
getNodeXPath(org.dom4j.Node node,
java.lang.String prefix) |
java.lang.String |
getRobotRecog(org.dom4j.Document document,
java.lang.String xpath)
Generate the RS in SAFS-Robot's format for element described by xpath.
|
java.lang.String |
getRobotRecognition(java.lang.String xpath,
boolean withName)
According to a xpath, return "SAFS recognition string"
|
SPCTreeNode |
getRobotRecognitionNode(java.lang.String xpath,
boolean withName)
According to a xpath, return SPCTreeNode containig
"SAFS recognition string", Html element's id, Html element's name
|
java.lang.String |
getSSBounds() |
java.lang.String |
getUniqueNameForXpath(java.lang.String url,
java.lang.String xpath,
java.lang.String prefix) |
java.lang.String |
getUrl() |
java.lang.String |
getXpath(org.dom4j.Document document,
java.lang.String[] tags,
java.lang.String[][] attributes,
int index,
boolean secondaryMatch,
boolean matchPartial)
This functions takes an array of (HTML) tags, a double array of
attributes to check,
and whether to check the text attributes for partial matches. |
void |
goBackToMainPage() |
boolean |
isMainPage()
When we call getAllElements(), if the html contains frame, we will try to
get html content with aid of API selenium.open(frameURL); selenium.getHtmlSource().
|
static void |
main(java.lang.String[] args) |
java.lang.String |
normalizeURL(java.lang.String url) |
org.dom4j.Document |
setDocument(java.lang.String urlString,
java.lang.String htmlSource,
boolean changeMainPageURL)
Purpose Get dom4j-DOM according to html-content
If the html-content is null, then try to get it according to the urlString. The method setHTTPProxy() may needs to be called before calling this method. |
void |
setHTTPProxy()
This is needed when we read the content from an URL
|
void |
setInterrupt(boolean interrupt) |
void |
test() |
public java.util.HashMap<java.lang.String,org.dom4j.Document> documents
public java.lang.String url
com.thoughtworks.selenium.Selenium selenium
SeleniumGUIUtilities util
public static final java.lang.String XPATH_ALL_LEVEL_PREFIX
public static final java.lang.String XPATH_ALL_ELEMENTS
public static final java.lang.String XPATH_ATTRIBUTES
public static final java.lang.String BOUDNS_SEPARATOR
public static final java.lang.String ASSIGN_SEPARATOR
public static final java.lang.String RECOGNITION_LEVEL_SEPARATOR
public int timeconsume1
public int timeconsume2
public int timeconsume3
public DocumentParser(java.lang.String url)
public DocumentParser(com.thoughtworks.selenium.Selenium selenium, SeleniumGUIUtilities util)
public boolean isMainPage()
public java.lang.String getBoundsSeparator()
public void setInterrupt(boolean interrupt)
public void setHTTPProxy()
public java.lang.String getUrl()
public org.dom4j.Document getDocument(java.lang.String url, boolean changeMainPageURL)
url
- a url stringchangeMainPageURL
- true if the main page url needs to be changedpublic org.dom4j.Document setDocument(java.lang.String urlString, java.lang.String htmlSource, boolean changeMainPageURL)
setHTTPProxy()
may needs to be called before calling this method.urlString
- From where to get the html-contenthtmlSource
- The html content to be converted to dom4j-DOMchangeMainPageURL
- true if the main page url needs to be changedpublic java.lang.String getEncodingName(java.io.InputStream ins) throws java.io.IOException
ins
- the input-stream to be parsedjava.io.IOException
public java.lang.String getInnerHtml(java.lang.String content, java.lang.String tag)
content
- from which to get innerHTMLtag
- to which the innerHTML belongspublic java.lang.String[] getAllElements()
public void getAllElementsR(org.dom4j.Document doc, java.lang.String prefix, int top, int left, java.lang.String docURL, java.util.List<java.lang.String> elementsXpathList)
doc
- From where to get nodesprefix
- The prefix to be added before node's xpathtop
- The y-coordination of the top-left point of docleft
- The x-coordination of the top-left point of docdocURL
- The url representing the docelementsXpathList
- A list contains all xpath, and it will be returned.public java.lang.String getFrameSrcURL(org.dom4j.Document document, java.lang.String xpath, java.lang.String parentURL)
document
- In this document, the xpath will be searched.xpath
- The xpath representing a frameparentURL
- The url where the frame resides; the first parameter documentpublic java.lang.String getFrameSrcURL(org.dom4j.Node frameNode, java.lang.String parentURL)
frameNode
- From where to get the value of attribute 'src'parentURL
- If the attribute 'src' of the frameNode contains a relativepublic java.lang.String normalizeURL(java.lang.String url)
public int getFrameTop(org.dom4j.Node frameNode)
public int getFrameLeft(org.dom4j.Node frameNode)
public java.util.HashMap getAttributes(java.lang.String url, java.lang.String xpath)
url
- The url representing the html page.xpath
- The xpath representing the element.public java.util.HashMap getAttributes(org.dom4j.Document doc, java.lang.String xpath)
doc
- Dom4j object Document, represent the document of html page.xpath
- The xpath representing the element.public java.util.HashMap getAttributes(org.dom4j.Node node)
node
- Dom4j object Node,representing the element on html page.public java.lang.String getAttribute(java.lang.String url, java.lang.String xpath, java.lang.String attribute)
url
- The url representing the html page.xpath
- An xpath representing an element on the web page.attribute
- The attribute's name.public java.lang.String getAttribute(org.dom4j.Document doc, java.lang.String xpath, java.lang.String attribute)
doc
- A DOM4J Document (org.dom4j.Document)xpath
- An xpath representing an element on the web page.attribute
- The attribute's name.public java.lang.String getAttribute(org.dom4j.Node node, java.lang.String attribute)
node
- A DOM4J Node (org.dom4j.Node)attribute
- The attribute's name.public void goBackToMainPage()
public java.lang.String getNodeXPath(org.dom4j.Node node, java.lang.String prefix)
public SPCTreeNode getRobotRecognitionNode(java.lang.String xpath, boolean withName)
xpath
- withName
- if true, a generated component name will be prefix of recognition stringpublic java.lang.String getRobotRecognition(java.lang.String xpath, boolean withName)
xpath
- withName
- if true, a generated component name will be prefix of recognition stringpublic java.lang.String getRobotRecog(org.dom4j.Document document, java.lang.String xpath)
document
- Where the element locates.xpath
- Xpath to describe an element. It should not contain any Frame.public org.dom4j.Element getElementFromXpath(org.dom4j.Document document, java.lang.String xpath)
document
- Where to search element for an xpathxpath
- The xpath to be matched.public java.lang.String getUniqueNameForXpath(java.lang.String url, java.lang.String xpath, java.lang.String prefix)
public int getIndex(org.dom4j.Document document, org.dom4j.Element element)
public java.util.List getElementsMatchingTags(org.dom4j.Document document, java.lang.String[] tags)
public java.util.List<java.lang.String> getAllXPath(org.dom4j.Document doc, java.lang.String[] tags)
public java.lang.String getXpath(org.dom4j.Document document, java.lang.String[] tags, java.lang.String[][] attributes, int index, boolean secondaryMatch, boolean matchPartial)
document
- In which document, the elements will be tested for matchingtags
- An array containing html-tags, among these elements, we select
one matched.attributes
- The attributes (name, value) needs to be matched for an
elementindex
- If there are several matched element according to tags and
atributes, indexsecondaryMatch
- boolean, if false, indicating this is the first time
searching.matchPartial
- boolean, if true, the attribute's value will be
partial-matched.public int getFrameIndex(org.dom4j.Document document, java.lang.String xpath)
public boolean checkAttributes(org.dom4j.Node node, java.lang.String[][] attrcheck, boolean matchPartial)
public java.lang.String getClientScrollInfo(com.thoughtworks.selenium.Selenium selenium) throws SAFSException
SAFSException
public java.lang.String getBrowserClientScreenPosition(com.thoughtworks.selenium.Selenium selenium) throws SAFSException
SAFSException
public java.lang.String getSSBounds()
public void test()
public static void main(java.lang.String[] args)
args
- Copyright © SAS Institute. All Rights Reserved.