def search(self, form_type, results_expected, fields, row_count, **kwargs):

        current.auth.override = True
        if isinstance(row_count, dict) and form_type == self.search.simple_form:
            key = row_count["key"]
            resource = current.s3db.resource(row_count["tablename"])
            simpleSearch = resource.search_method().simple[0]
            if len(fields) == 0:
                fields = ({"name":simpleSearch[0],"value":key},)
            searchFields = simpleSearch[1].field
            for i in xrange(len(searchFields)):
                if i == 0:
                    query = (FS(searchFields[i]).like("%" + key + "%"))
                else:
                    query |= (FS(searchFields[i]).like("%" + key + "%"))

            filters = row_count.get("filters", None)
            if filters is not None:
                for filter in filters:
                    qfilter = (resource.table[filter[0]] == filter[1])
                    resource.add_filter(qfilter)

            resource.add_filter(query)
            row_count = resource.count()

        browser = self.browser

        clear_button = browser.find_elements_by_xpath("//a[text()='Clear']")
        if clear_button[0].is_displayed() :
           clear_button[0].click()
        else:
           clear_button[1].click()


        try:
            if form_type == self.search.advanced_form:
                link = browser.find_element_by_xpath("//a[@class='action-lnk advanced-lnk']")
            elif form_type == self.search.simple_form:
                link = browser.find_element_by_xpath("//a[@class='action-lnk simple-lnk']")
        except NoSuchElementException:
            # There might be no link if one of the forms is the only option
            link = None

        if link and link.is_displayed():
            link.click()

        time.sleep(1)

        self.fill_fields(fields)

        if isinstance(row_count, dict) and form_type == self.search.advanced_form:
            resource = current.s3db.resource(row_count["tablename"])
            search_list = resource.search_method().advanced
            for search in search_list:
                widget = search[1]
                if isinstance(widget, S3SearchOptionsWidget):
                    values = []
                    elem_list = browser.find_elements_by_name(widget.attr._name)
                    for elem in elem_list:
                        if elem.get_attribute("checked"):
                            values.append(int(s3_unicode(elem.get_attribute("value"))))
                    if len(values) > 0:
                        query = widget.query(resource,values)
                        resource.add_filter(query)

            filters = row_count.get("filters", None)
            if filters is not None:
                for filter in filters:
                    qfilter = (resource.table[filter[0]] == filter[1])
                    resource.add_filter(qfilter)

            row_count = resource.count()


        browser.find_element_by_name(("simple_submit", "advanced_submit")[form_type]).click()

        time.sleep(1)

        if results_expected:
            self.assertFalse(
            browser.find_element_by_id("table-container").text
                    == "No Records Found",
                "No results found, when results expected.")
        else:
            return

        # We"re done entering and submitting data; now we need to check if the
        # results produced are valid.
        htmlRowCount = self.dt_row_cnt()[2]
        successMsg = "DB row count (" + str(row_count) + ") matches the HTML datatable row count (" + str(htmlRowCount) + ")."
        failMsg = "DB row count (" + str(row_count) + ") does not match the HTML datatable row count (" + str(htmlRowCount) + ")."
        self.assertTrue(row_count == htmlRowCount, failMsg)
        self.reporter(successMsg)

        if "data" in kwargs.keys():
            self.assertTrue(bool(kwargs["data"](self.dt_data())),
                "Data verification failed.")

        if "manual_check" in kwargs.keys():
            self.assertTrue(bool(kwargs["manual_check"](self)),
                "Manual checks failed.")

        if "match_row" in kwargs.keys():
            data = self.dt_data(row_list=(kwargs["match_row"][0]))
            kwargs["match_row"] = kwargs["match_row"][1:]
            for a, b in zip(kwargs["match_row"], data):
                self.assertTrue(a == b,
                    "Row match failed.")

        if "match_column" in kwargs.keys():
            column_index = kwargs["match_column"][0]
            kwargs["match_column"] = kwargs["match_column"][1:]
            shown_items = [dt_data_item(column=column_index,
            row=r) for r in xrange(1, len(kwargs["match_column"]) + 1)]
            for item in kwargs["match_column"]:
                self.assertTrue(item in shown_items)

        return self.dt_data()
Generic method to test the validity of search results.
dataset/ETHPy150Open sahana/eden/modules/tests/web2unittest.py/SeleniumUnitTest.search