Пример #1
0
 def _parse_clickable_from_db_to_model(self, clickable):
     c = Clickable(clickable['event'], clickable['tag'], clickable['dom_address'], clickable['html_id'], clickable['html_class'], clickable['clickable_depth'], clickable['function_id'])
     c.clicked = clickable['clicked']
     c.clickable_type = self._num_to_clickable_type(clickable['clickable_type'])
     c.links_to = clickable['links_to']
     c.clickable_depth = clickable['clickable_depth']
     return c
Пример #2
0
    def test_clickables(self):
        clickable1 = Clickable("click",
                               "a",
                               "body/div/div/a",
                               id="Test1",
                               html_class="Test2",
                               clickable_depth=243,
                               function_id="Test3")
        self.database._insert_clickable_into_db(SESSION, WEBPAGE_ID,
                                                clickable1)

        clickables = self.database.get_all_clickables_to_page_id_from_db(
            SESSION, WEBPAGE_ID)
        self.assertEqual(len(clickables), 1)
        self.assertEqual(clickable1, clickables[0])

        self.database.set_clickable_clicked(
            SESSION,
            WEBPAGE_ID,
            clickable1.dom_address,
            clickable1.event,
            clickable_depth=243,
            clickable_type=ClickableType.CreatesNewNavigatables)

        clickables = self.database.get_all_clickables_to_page_id_from_db(
            SESSION, WEBPAGE_ID)
        self.assertEqual(len(clickables), 1)
        clickable1.clicked = True
        clickable1.clickable_type = ClickableType.CreatesNewNavigatables
        self.assertEqual(clickable1, clickables[0])
Пример #3
0
 def get_all_clickables_to_page_id_from_db(self, current_session, page_id):
     clickables = self.clickables.find({"web_page_id": page_id, "session": current_session})
     result = []
     for clickable in clickables:
         c = Clickable(clickable['event'], clickable['tag'], clickable['dom_address'], clickable['html_id'], clickable['html_class'], clickable_depth=clickable['clickable_depth'], function_id=clickable['function_id'])
         c.links_to = clickable['links_to']
         c.clickable_type = self._num_to_clickable_type(clickable['clickable_type'])
         c.clicked = clickable['clicked']
         result.append(c)
     return result
Пример #4
0
 def loadData(fn):
     indata = json.load(open(fn))
     url = indata["url"]
     initclick = Clickable.fromDict(
         indata["element_to_click"]
     ) if indata["element_to_click"] != None else None
     preclicks = [
         Clickable(None, None, None).fromDict(x) if x != None else None
         for x in indata["pre_clicks"]
     ]
     return url, initclick, preclicks
Пример #5
0
 def add_eventlistener_to_element(self, msg):
     #logging.debug(msg)
     if "id" in msg and msg['id'] != "":
         id = msg['id']
     else:
         id = None
     dom_address = msg['addr']
     event = msg['event']
     if event == "":
         event = None
     tag = msg['tag']
     if "class" in msg and msg['class'] != "":
         html_class = msg['class']
     else:
         html_class = None
     function_id = msg['function_id']
     if tag is not None and dom_address != "":
         tmp = Clickable(event,
                         tag,
                         dom_address,
                         id,
                         html_class,
                         function_id=function_id)
         if tmp not in self._new_clickables:
             self._new_clickables.append(tmp)
Пример #6
0
def _extract_new_links_from_links(elements, requested_url):
    found_links = []
    new_clickables = []
    if (len(elements) == 0):
        #logging.debug("No links found...")
        return [], []
    else:
        for elem in elements:
            href = elem.attribute("href")
            #logging.debug(str(type(elem)) + " href: " + str(href) + " Tagname: " + str(elem.tagName()))
            if href == "/" or href == requested_url or href == "":  #or href[0] == '#':
                continue
            elif "javascript:" in href:  #We assume it as clickable
                html_id = elem.attribute("id")
                html_class = elem.attribute("class")
                dom_address = elem.evaluateJavaScript("getXPath(this)")
                event = href
                tag = "a"
                new_clickables.append(
                    Clickable(event, tag, dom_address, html_id, html_class,
                              None, None))
            elif "#" in href:
                html_id = elem.attribute("id")
                html_class = elem.attribute("class")
                dom_address = elem.evaluateJavaScript("getXPath(this)")
                event = "click"
                tag = "a"
                new_clickables.append(
                    Clickable(event, tag, dom_address, html_id, html_class,
                              None, None))
            elif len(href) > 0:
                html_id = elem.attribute("id")
                html_class = elem.attribute("class")
                dom_address = elem.evaluateJavaScript("getXPath(this)")
                url = href
                link = Link(url, dom_address, html_id, html_class)
                found_links.append(link)
            else:
                logging.debug(
                    "Elem has attribute href: " +
                    str(elem.attribute("href") + " and matches no criteria"))
    return found_links, new_clickables
Пример #7
0
 def get_all_clickables_to_page_id_from_db(self, current_session, page_id):
     clickables = self.clickables.find({
         "web_page_id": page_id,
         "session": current_session
     })
     result = []
     for clickable in clickables:
         c = Clickable(clickable['event'],
                       clickable['tag'],
                       clickable['dom_address'],
                       clickable['html_id'],
                       clickable['html_class'],
                       clickable_depth=clickable['clickable_depth'],
                       function_id=clickable['function_id'])
         c.links_to = clickable['links_to']
         c.clickable_type = self._num_to_clickable_type(
             clickable['clickable_type'])
         c.clicked = clickable['clicked']
         result.append(c)
     return result
Пример #8
0
 def _parse_clickable_from_db_to_model(self, clickable):
     c = Clickable(clickable['event'], clickable['tag'],
                   clickable['dom_address'], clickable['html_id'],
                   clickable['html_class'], clickable['clickable_depth'],
                   clickable['function_id'])
     c.clicked = clickable['clicked']
     c.clickable_type = self._num_to_clickable_type(
         clickable['clickable_type'])
     c.links_to = clickable['links_to']
     c.clickable_depth = clickable['clickable_depth']
     return c
def property_helper(frame):
    all_elements = frame.findAllElements("*")
    result = []
    properties = ['onclick', "onmouseover", "onabort", "onblur", "onchange", "onblclick", "onerror", "onfocus", "onkeydown",
                  "onkeypress", "onkeyup", "onmousedown", "onmousemove", "onmouseout", "onmouseup"]
    for element in all_elements:
        element_id = None
        element_class = None
        if element.hasAttribute("id"):
            element_id = element.attribute("id")
        if element.hasAttribute("class"):
            element_class = element.attribute("class")
        element_dom_address = None
        for prop in properties:
            if element.hasAttribute(prop):
                if element_dom_address is None:
                    element_dom_address = element.evaluateJavaScript("getXPath(this)")
                result.append(Clickable(prop, element.tagName(), element_dom_address, element_id, element_class, function_id="None"))
    return result
Пример #10
0
 def test_webpage(self):
     clickable1 = Clickable("click",
                            "a",
                            "body/div/div/a",
                            id="Test1",
                            html_class="Test2",
                            clickable_depth=243,
                            function_id="Test3")
     web_page = WebPage(1,
                        url=TEST_URL1,
                        html=TEST_HTML,
                        cookiesjar=None,
                        depth=24,
                        base_url=TEST_URL2)
     web_page.clickables.extend([clickable1])
     self.database.insert_page_into_db(SESSION, web_page)
     web_page1 = self.database.get_webpage_to_id_from_db(SESSION, 1)
     self.assertEqual(web_page.toString(), web_page1.toString())
     web_page2 = self.database.get_webpage_to_url_from_db(
         SESSION, TEST_URL1)
     self.assertEqual(web_page.toString(), web_page2.toString())
Пример #11
0
 def __init__(self, clickable, key_event):
     Clickable.__init__(self, clickable.event, clickable.tag, clickable.dom_address, clickable.id, clickable.html_class, clickable.clickable_depth, clickable.function_id)
     self.random_char = key_event #Is the key typed in for triggering the clickabel
Пример #12
0
from models.url import Url
from models.webpage import WebPage

__author__ = 'constantin'

import unittest

SESSION = 12345
WEBPAGE_ID = 99
TEST_URL1 = "http://example.com"
TEST_URL2 = "http://example.com/exmaple.php"
TEST_HTML = "<html><head></head><body></body></html>"
CLICKABLE = Clickable("click",
                      "a",
                      "body/div/div/a",
                      id="Test1",
                      html_class="Test2",
                      clickable_depth=243,
                      function_id="Test3")
WEBPAGE = WebPage(1,
                  url=TEST_URL1,
                  html=TEST_HTML,
                  cookiesjar=None,
                  depth=24,
                  base_url=TEST_URL2)
AJAXREQUEST = AjaxRequest("GET",
                          TEST_URL1,
                          CLICKABLE,
                          parameters=["test=Test"])

Пример #13
0
 def __init__(self, clickable, key_event):
     Clickable.__init__(self, clickable.event, clickable.tag,
                        clickable.dom_address, clickable.id,
                        clickable.html_class, clickable.clickable_depth,
                        clickable.function_id)
     self.random_char = key_event  #Is the key typed in for triggering the clickabel