コード例 #1
0
    def do_multichoice(self, element_IDs):
        """
        Attempts to answer the multiple choice
            element_IDs - A list of all element IDs for the current question : List
            element_IDs -> Boolean
        """
        if self.verbose >= 2:
            print("[*]%i: Doing MultiChoice" % self.ID)

        # Identify if there is an 'other' textbox
        if "_other" in element_IDs[-1]:
            other_ID = element_IDs.pop()
        else:
            other_ID = None

        # Select a random multi-choice
        element_ID_i = randint(0, len(element_IDs) - 1)
        element_ID = element_IDs[element_ID_i]
        element = self.driver.find_element_by_id(element_ID)
        element.click()
        self.lock.acquire()
        self.choices.append(element_ID)
        self.lock.release()

        # If 'other' is checked answer the textbox
        if element_ID_i == len(element_IDs) - 1 and other_ID is not None:
            element = self.driver.find_element_by_id(other_ID)
            self.lock.acquire()
            element.send_keys(get_sentence())
            self.lock.release()

        if self.verbose >= 2:
            print("[*]%i: MultiChoice annswered" % self.ID)
        return True
def action_wrapper(hermes, intentMessage, conf):
    session_id = intentMessage.session_id
    print("action_wrapper")
    print_intentMessage(intentMessage)
    save_intentMessage(intentMessage,
                       "tmp/{}_messageInfo.txt".format(session_id))
    sentence = get_sentence()
    hermes.publish_end_session(intentMessage.session_id, sentence)
コード例 #3
0
    def do_checkbox(self, element_IDs):
        """
        Attempts to answer the checkbox
            element_IDs - A list of all element IDs for the current question : List
            element_IDs -> Boolean
        """
        if self.verbose >= 2:
            print("[*]%i: Doing CheckBox" % self.ID)
        checkbox = []

        # Identify if there is an 'other' textbox
        if "_other" in element_IDs[-1]:
            other_ID = element_IDs.pop()
        else:
            other_ID = None

        # Weighted randomised checkboxs
        for _ in range(0, len(element_IDs)):
            if randint(0, len(element_IDs) - 1) == 0:
                checkbox.append(True)
            else:
                checkbox.append(False)

        # Check at least one checkbox is checked
        if True not in checkbox:
            i = randint(0, len(element_IDs) - 1)
            checkbox[i] = True

        # Go through all elements and check them based on checkbox
        for element_ID_i in range(0, len(element_IDs)):
            if checkbox[element_ID_i]:
                element_ID = element_IDs[element_ID_i]
                element = self.driver.find_element_by_id(element_ID)
                self.lock.acquire()
                element.click()
                self.lock.release()
                self.choices.append(element_ID)

                # If 'other' is checked answer the textbox
                if element_ID_i == len(
                        element_IDs) - 1 and other_ID is not None:
                    element = self.driver.find_element_by_id(other_ID)
                    self.lock.acquire()
                    element.send_keys(get_sentence())
                    self.lock.release()

        if self.verbose >= 2:
            print("[*]%i: CheckBox answered" % self.ID)
        return True
コード例 #4
0
    def do_comment(self, element):
        """
        Attempts to answer the comment box
            element - The comment box element : selenium object
            element -> Boolean
        """
        if self.verbose >= 2:
            print("[*]%i: Doing CommentBox" % self.ID)
        self.lock.acquire()
        element.send_keys(get_sentence())
        self.lock.release()

        if self.verbose >= 2:
            print("[*]%i: CommentBox answered" % self.ID)
        return True