Exemplo n.º 1
0
 def find_all_by_xpath(self, xpath):
     """ Return all nodes matching the given XPath 2.0 expression. """
     try:
         return [
             self.__node(node_id) for node_id in self.__run_js(
                 Utils.qt_js_prepare('Qt.findXpath("{0}")'.format(
                     Utils.normalize_quotes(xpath)))).split(",") if node_id
         ]
     except AttributeError:
         return None
Exemplo n.º 2
0
 def wait_until_css(self, selector, timeout=30):
     node = self.find_by_css(selector)
     elapsed = 0
     while not node:
         if elapsed > timeout:
             return None
         Utils.wait(1000)
         elapsed += 1
         node = self.find_by_css(selector)
     return node
Exemplo n.º 3
0
 def wait_until_xpath(self, xpath, timeout=30):
     node = self.find_by_xpath(xpath)
     elapsed = 0
     while not node:
         if elapsed > timeout:
             return None
         Utils.wait(1000)
         elapsed += 1
         node = self.find_by_xpath(xpath)
     return node
Exemplo n.º 4
0
 def find_all_by_css(self, selector):
     """ Return all nodes matching the given CSSv3 expression. """
     try:
         return [
             self.__node(node_id) for node_id in self.__run_js(
                 Utils.qt_js_prepare('Qt.findCss("{0}")'.format(
                     Utils.normalize_quotes(selector)))).split(",")
             if node_id
         ]
     except AttributeError:
         return None
Exemplo n.º 5
0
 def find_all_by_xpath(self, xpath):
     """ Finds another node by XPath originating at the current node. """
     try:
         return [
             self.__node(node_id) for node_id in self.__run_js(
                 Utils.qt_js_prepare(
                     'Qt.findXpathRelativeTo(Qt.getNode({0}), "{1}")'.
                     format(self.node_id, Utils.normalize_quotes(
                         xpath)))).split(",") if node_id
         ]
     except AttributeError:
         return None
Exemplo n.º 6
0
 def find_all_by_css(self, selector):
     """ Finds another node by a CSS selector relative to the current node. """
     try:
         return [
             self.__node(node_id) for node_id in self.__run_js(
                 Utils.qt_js_prepare(
                     'Qt.findCssRelativeTo(Qt.getNode({0}), "{1}")'.format(
                         self.node_id, Utils.normalize_quotes(
                             selector)))).split(",") if node_id
         ]
     except AttributeError:
         return None
Exemplo n.º 7
0
 def left_click(self):
     """ Left clicks the current node, then waits for the page to fully load. """
     loop = QEventLoop()
     self.__parent._qt_invocation.async_js_finished.connect(loop.quit)
     self.__run_js(
         Utils.qt_js_prepare('Qt.click("{0}")').format(self.node_id))
     loop.exec()
     print('after click')
Exemplo n.º 8
0
 def save_image(self, path, name='untitled'):
     b64 = self.__run_js(
         Utils.qt_js_prepare('Qt.img2b64("{0}")'.format(self.node_id)))
     if b64 is not None and b64.startswith('data:'):
         b64 = b64.split(',')
         if len(b64) > 1:
             img_b64 = b64[-1]
             if not os.path.exists(path):
                 os.mkdir(path)
             f = open(path + '/' + name + '.png', 'wb')
             f.write(base64.b64decode(img_b64))
             f.close()
Exemplo n.º 9
0
 def is_visible(self):
     """ Checks whether the current node is visible. """
     return self.__run_js(
         Utils.qt_js_prepare('Qt.visible("{0}")'.format(self.node_id)))
Exemplo n.º 10
0
 def select_option(self):
     """ Selects an option node. """
     self.__run_js(
         Utils.qt_js_prepare('Qt.selectOption("{0}")'.format(self.node_id)))
Exemplo n.º 11
0
 def set_value(self, value):
     """ Sets the node content to the given value (e.g. for input fields). """
     self.__run_js(
         Utils.qt_js_prepare('Qt.set("{0}","{1}")'.format(
             self.node_id, value)))
Exemplo n.º 12
0
 def submit(self):
     """ Submits a form node, then waits for the page to completely load. """
     self.__run_js(
         Utils.qt_js_prepare('Qt.submit("{0}")'.format(self.node_id)))
Exemplo n.º 13
0
    def search(self, region_letter, number):
        if self.__login():
            print('**enter number and region')
            region = self.robot.wait_until_xpath("/html/body/div[1]/div[4]/div[1]/div/div[2]/div[1]/div/select")
            region_options = region.find_all_by_css('option')
            for o in region_options:
                if o.get_value() == region_letter:
                    o.select_option()

            #
            input_number = self.robot.find_by_xpath("/html/body/div[1]/div[4]/div[1]/div/div[2]/div[1]/input")
            input_number.set_value(number)
            #     print(input_number.get_value())
            print('set number')
            input_number.enter()
            print('before wait')
            Utils.wait(2001)

            print('8888888888')
            result = {}
            print('before find')
            profilename = self.robot.wait_until_css('div.ProfileName')
            print('after find ', profilename.get_attribute('class'))
            if profilename:
                print('a')
                print('b')
                profilename_box = profilename.find_by_css('div')
                print('cc')
                profilename_text = profilename_box.get_text()
                print('after tex pro')
                print(1111, profilename_text)
                if 'is not yet available' in profilename_text:
                    print('b')
                    result['profileName'] = 'is not yet available'
                else:
                    print('c')
                    result['profileName'] = profilename_text
                    list_info = self.robot.find_by_css('div.ProfileDetails.ProfileContainer')
                    if list_info:
                        number_info = self.robot.find_by_xpath('/div[1]/div/div[2]')
                        if number_info:
                            number = number_info.find_by_xpath('/div[1]')
                            operator = number_info.find_by_xpath('/div[2]')

                            if number:
                                result['number'] = number
                            if operator:
                                result['operator'] = operator

                        location = self.robot.find_by_xpath('/div[2]/a/div[2]/div')
                        if location:
                            result['location'] = location
            else:
                print('fffffff')


            print('***', result)
            with open(BASE_APP_PATH + '/modules/truecaller/v_1_0/storage/' + self.proccess_id + '.pkl', 'wb') as f:
                pickle.dump(result, f)
                f.close()
            Utils.wait(3000)
            print('eeeeeeeeeeeeeeeeeeeeeeeeeeeend')
            sys.exit()
Exemplo n.º 14
0
 def is_attached(self):
     """ Checks whether the current node is actually existing on the currently active web page. """
     return self.__run_js(
         Utils.qt_js_prepare('Qt.isAttached("{0}")'.format(self.node_id)))
Exemplo n.º 15
0
 def focus(self):
     """ Puts the focus onto the current node, then waits for the page to fully load. """
     self.__run_js(
         Utils.qt_js_prepare('Qt.focus("{0}")'.format(self.node_id)))
Exemplo n.º 16
0
 def get_center_position(self) -> dict:
     """ Return the current node center {x,y} position """
     return self.__run_js(
         Utils.qt_js_prepare('Qt.centerPosition("{0}")'.format(
             self.node_id)))
Exemplo n.º 17
0
 def get_position(self) -> dict:
     """ Return the current node rect position """
     return self.__run_js(
         Utils.qt_js_prepare('Qt.position("{0}")').format(self.node_id))
Exemplo n.º 18
0
    def enter(self):
        """ press enter on the node|element """
        self.__run_js(
            Utils.qt_js_prepare('Qt.enter("{0}")').format(self.node_id))

        print('after enter')
Exemplo n.º 19
0
 def get_text(self) -> str:
     """ Returns the inner text (not HTML). """
     return self.__run_js(
         Utils.qt_js_prepare('Qt.text("{0}")').format(self.node_id))
Exemplo n.º 20
0
 def get_xpath(self):
     """ Returns an XPath expression that uniquely identifies the current node. """
     return self.__run_js(
         Utils.qt_js_prepare('Qt.path("{0}")'.format(self.node_id)))
Exemplo n.º 21
0
 def get_tag_name(self):
     """ Returns the tag name of the current node. """
     return self.__run_js(
         Utils.qt_js_prepare('Qt.tagName("{0}")'.format(self.node_id)))
Exemplo n.º 22
0
 def unselect_options(self):
     """ Unselects an option node (only possible within a multi-select). """
     self.__run_js(
         Utils.qt_js_prepare('Qt.unselectOption("{0}")'.format(
             self.node_id)))
Exemplo n.º 23
0
 def get_value(self):
     """ Return the node`s value. """
     return self.__run_js(
         Utils.qt_js_prepare('Qt.value("{0}")'.format(self.node_id)))