Beispiel #1
0
    def select_dropdown_option(self, dropdown_element: WebElement,
                               expected_value: str) -> bool:
        """
        Checks if the given value is present in a select (dropdown) element. If yes, selects the option.
        :return: True if the option is present, else False.
        """
        # Todo: Bootstrap does not play dropdown with Selenium :(
        # See https://flowfx.de/blog/testing-bootstrap-select-dropdown-field-with-selenium-python/

        if expected_value not in list(
                map(lambda o: o.text.lstrip().rstrip(),
                    Select(dropdown_element).options)):
            return False

        # Approach 1:
        # dropdown_element.click()
        # dropdown_element.send_keys(expected_value)
        # dropdown_element.send_keys(Keys.ENTER)
        # return True

        # Approach 2:
        dropdown_element.click()
        options = dropdown_element.find_elements_by_tag_name('option')
        for opt in options:
            if expected_value == opt.text.lstrip().rstrip():
                opt.click()
                return True
        return False
    def extract_dates(self, table: WebElement):
        date_table = []
        rows = table.find_elements_by_tag_name('tr')
        for row in rows[1:]:
            try:
                fields = row.find_elements_by_tag_name('td')
                raw_time = fields[1].text
                times = re.findall('(\d\d:\d\d)', raw_time)

                raw_dates = fields[3].text
                dates = re.findall('(\d\d.\d\d.\d\d\d\d)', raw_dates)

                day = fields[0].text

                rythm = fields[2].text

                from_time = times[0]
                to_time = times[1]

                from_date = dates[0]
                to_date = dates[1]

                room = fields[6].text

                date_table.append(
                    (day, rythm, from_time, to_time, from_date, to_date, room))
            except Exception:
                pass
        return date_table
Beispiel #3
0
 def __extract_choosables(self, choosables: WebElement):
     answer_choosable = choosables.find_elements_by_tag_name(
         name=self.__choosable_tag_name)
     self.__answer_choosables = dict()
     for choosable in answer_choosable:
         self.__answer_choosables[choosable.text.split('. ')[0]] = \
             choosable
Beispiel #4
0
 def create(row: WebElement) -> 'Auction':
     cols = row.find_elements_by_tag_name('td')
     name = cols[Auction._NAME_ID].text
     lvl_profession_raw: str = cols[Auction._LVL_PROFESSION_ID].text
     lvl = int(lvl_profession_raw.split(' ')[0])
     profession = Profession.find(lvl_profession_raw)
     character = Character(name, profession, lvl)
     price = int(str(cols[Auction._PRICE_ID].text).split(' ')[0])
     return Auction(character, price)
Beispiel #5
0
def get_info(tab_element: WebElement, jid: str):

    trs = tab_element.find_elements_by_tag_name("tr")
    logger.info(trs)
    logger.info("----")
    jj_file = open("{}.txt".format(jid), mode="a+")
    for tr in trs:
        print(tr.text)
        data_text = tr.text
        if len(data_text.split(" ")) >= 6:
            dlist = data_text.split(" ")
            jdate, jvalue, jper = dlist[0], dlist[1], dlist[3]
        else:
            dlist = data_text.split(" ")
            jdate, jvalue, jper = dlist[0], dlist[1], dlist[2]
        jj_file.write("{} {} {}\n".format(jdate, jvalue, jper[:-1]))
    jj_file.close()
Beispiel #6
0
def get_page_text(page_div: WebElement) -> str:
    p_list: List[WebElement] = page_div.find_elements_by_tag_name("p")
    count = len(p_list)
    text = ""
    for i in range(0, count):
        p_text: str = p_list[i].text.strip()
        if i == 0 or i == count - 1:
            text += p_text
        else:
            if p_text.strip() == "":
                next_text = p_list[i + 1].text.strip()
                if next_text == "":
                    text += ""
                else:
                    text += "\n"
            else:
                text += p_text.strip()
    return text
 def from_element(element: WebElement, ignore_size=False):
     try:
         ignored_exceptions = (
             NoSuchElementException,
             StaleElementReferenceException,
         )
         WebDriverWait(element, 3,
                       ignored_exceptions=ignored_exceptions).until(
                           EC.presence_of_all_elements_located(
                               (By.CLASS_NAME,
                                "files-id")))  # type: WebElement
     except TimeoutException:
         return None
     file = File()
     for i, col in enumerate(element.find_elements_by_tag_name("td")):
         if i >= len(File.FILE_LIST_COLUMN_DATA_TYPE_ORDER):
             continue
         data_type = File.FILE_LIST_COLUMN_DATA_TYPE_ORDER[i]
         if data_type == "id":
             file.id = col.find_element_by_tag_name("input").get_attribute(
                 "value")
         elif data_type == "name":
             file.name = col.text
             file.remote_location = col.find_element_by_tag_name(
                 "a").get_attribute("href")
         elif data_type == "size":
             try:
                 calc_size_button = col.find_element_by_tag_name("button")
                 if not ignore_size:
                     calc_size_button.click()
                     while col.text == "berechnen":
                         time.sleep(0.1)
                     file.parse_size(col.text)
             except NoSuchElementException:
                 file.parse_size(col.text)
         elif data_type == "type":
             file.type = col.text
         elif data_type == "owner":
             file.owner = col.text
         elif data_type == "last_change":
             file.parse_last_change(col.text)
     return file
Beispiel #8
0
 def get_available_dates_in_week(week_cal: WebElement) -> list:
     day_list = week_cal.find_elements_by_tag_name("td")
     return [day for day in day_list if Checker.is_day_available(day)]
Beispiel #9
0
 def get_available_dates_in_month(month: WebElement) -> list:
     week_list = month.find_elements_by_tag_name("tr")[3:9]
     return [item for week in week_list for item in Checker.get_available_dates_in_week(week)]
Beispiel #10
0
def get_element_text(row: WebElement):
    cols = row.find_elements_by_tag_name("td")
    if not cols or len(cols) < 2:
        return ''

    return cols[1].text