Ejemplo n.º 1
0
def citidownload(wd: webdriver, orga, ptrack, pacc=None):
    accountNamesWords = ['interest checking', 'savings plaus']
    re1 = re.compile('\s*\-\s*')
    try:
        print('-----------citidownload')
        wd.implicitly_wait(10)
        # WebDriverWait(wd, 10).until(EC.presence_of_element_located((By.XPATH, '')))
        webArchs = wd.find_elements(By.TAG_NAME, 'a')
        print('-----------citidownload, 1')
        for arch in webArchs:
            print('-----------citidownload, 2')
            stext = arch.get_attributes('text')
            print('-----------citidownload, 3, ', stext)
            satext = re1.split(stext.strip())
            if len(satext) != 2:
                continue
            if satext[0] not in accountNamesWords:
                continue
            if len(satext[1]) != 4:
                continue
            try:
                last4digis = int(satext[0])
            except Exception as e:
                continue
            href = arch.get_attributes('href')
            if href.find('JFP_TOKEN') <= 10:
                continue
            arch.click()
            dropDowns = wd.find_elements(
                (By.XPATH, '//div[@class="dropdown"]/svg'))
            for dropDown in dropDowns:
                lastDaysWe = dropDown.find_element(
                    (By.XPATH, 'preceding-sibling::::div'))
                lastDays = lastDays.get_attributes('text')
                if lastDays[-4:] == 'days' or lastDays[
                        -6:] == 'months' or lastDays == 'specific date' or lastDays == 'customdaterange':
                    if lastDays != 'custom date range':
                        dropDown.click()
                        break
            startDateEle = None
            endDateEle = None
            downloadEle = None
            downloadEle.click()
            QFXEles = wd.find_elements((By.XPATH, '//input[@type="radio"]'))
            for aQFX in QFXEles:
                aQFXText = aQFX.get_attributes('text')
                if aQFXText[:3] == 'QFX':
                    btns = wd.find_elements(
                        (By.XPATH, '//button[@type="button"]'))
                    for btn in btns:
                        btnTxt = btn.get_attributes('text')
                        if btnTxt.lower() == 'download':
                            btnTxt.click()
                            closeEle = wd.find_elements((By.XPATH, '//'))
                            closeEle.click()
                            break
            #loop Download directory and find the newest one and move to data directory
    except Exception as e:
        tb.print_tb(e.__traceback__)
        print(e)
Ejemplo n.º 2
0
    def get_dict_qle(driver: webdriver) -> Dict[str, QuestionLabelElements]:
        q_element_labels: List[FirefoxWebElement] = driver.find_elements(
            By.XPATH, IndeedConstants.XPath.ALL_QUESTION_LABELS)
        q_element_inputs: List[FirefoxWebElement] = driver.find_elements(
            By.XPATH, IndeedConstants.XPath.ALL_QUESTION_INPUTS)

        dict_qle: Dict[str, QuestionLabelElements] = OrderedDict()
        for element_input in q_element_inputs:
            element_name = element_input.get_attribute(
                HTMLConstants.Attributes.NAME)

            if element_input.get_attribute(
                    HTMLConstants.Attributes.TYPE
            ) == HTMLConstants.InputTypes.HIDDEN:
                pass
            else:
                if dict_qle.get(element_name, None) is None:
                    qle = QuestionLabelElements()
                    qle.add_element(element_input)
                    qle.question.name = element_name
                    dict_qle[element_name] = qle
                else:
                    dict_qle[element_name].add_element(element_input)

        # Match Labels to Inputs
        for element_label in q_element_labels:
            label_for = element_label.get_attribute(
                HTMLConstants.Attributes.FOR)
            xpath_element_name = IndeedConstants.XPath.compute_xpath_input_name_of_label(
                label_for)
            element_name = driver.find_element(
                By.XPATH, xpath_element_name).get_attribute(
                    HTMLConstants.Attributes.NAME)
            label_text = element_label.get_attribute(
                HTMLConstants.Attributes.INNER_TEXT)
            if dict_qle.get(element_name, None) is None:
                print('No input for label ' + label_text)
            else:
                dict_qle[element_name].label = label_text

        for key, qle in dict_qle.items():
            qle.compute_question(driver)

        return dict_qle
Ejemplo n.º 3
0
def impOne(anOrga, anAcc, ptrack=None, driver: webdriver = None):
    wd = driver if driver is not None else makeChromeDriver()
    try:
        wd.get(anOrga['url'])
        bodyhtml = driver.find_elements(
            By.TAG_NAME, 'body')[0].get_attribute('innerHTML').lower()
        login(wd, anOrga, anAcc, bodyhtml)
        findAndDownload(wd, anOrga, anAcc, ptrack, bodyhtml)
        impFile()
    except:
        pass
    finally:
        if driver is None:
            wd.close()
Ejemplo n.º 4
0
    def _get_element(self, driver: webdriver, reference=None):
        """
        return the specified element
        :param driver: Selenium Driver
        :param reference: (optional) Identifier of the specific item (where the element is not enough)
        :param timeout: (optional) number of seconds for timeout
        :return: Selenium Element(s)
        """

        try:
            values = driver.find_elements(self.selector_type,
                                          self.selector_value)
            if reference is None:
                return values
            return values[reference]

        except NoSuchElementException:
            self.raise_not_found()
Ejemplo n.º 5
0
def indexed_dropdown_select_helper(driver: webdriver, by: By, identifier: str,
                                   value: str, index: int) -> None:
    """
    Looks for a given element in a dropdown menu where
    the dropdown menu id is not unique.
    This happens on JavaScript built pages
    or in bootstrap pages occasionally.
    :param driver: webdriver object.
    :param by: By type.
    :param identifier: element identifier.
    :param value: value to search for.
    :param index: index of list of non unique id dropdown list to search.
    :return:
    """
    if value != '':
        try:
            Select(
                driver.find_elements(by, identifier)[index])\
                .select_by_visible_text(value)
        except NoSuchElementException:
            pass
    else:
        pass
Ejemplo n.º 6
0
def courseDetails(driver: webdriver, url: str):
    driver.get(url)
    #time.sleep(7)
    l = WebDriverWait(driver, timeout=10).until(
        expected_conditions.presence_of_element_located(
            (By.CSS_SELECTOR, "div[jsname='rymPhb']")))
    # while not WebDriverWait(driver, timeout=10).until(expected_conditions.element_to_be_clickable(l.find_element_by_tag_name("div"))):
    # time.sleep(2)
    check_height = driver.execute_script("return document.body.scrollHeight;")
    while True:
        driver.execute_script(
            "window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(4)
        height = driver.execute_script("return document.body.scrollHeight;")
        if height == check_height:
            break
        check_height = height
    pg = BeautifulSoup(driver.page_source, "lxml")
    temp = pg.find(name="div", attrs={"jsname": "rymPhb"})
    assign, material, text = [], [], []
    for i in range(len(temp.contents)):
        if len(temp.contents[i]["class"]) > 4:
            j = temp.contents[i].contents[0].contents[0].contents
            text = j[2].contents[0].contents[1].contents[0].string.split(
                ": ")[1]
            date = j[2].contents[1].contents[1].string
            if j[0]["aria-label"][0] == "A":
                assign.append([i, text, date])
            else:
                material.append([i, text, date])
    time.sleep(3)
    total = driver.find_elements(By.CSS_SELECTOR, "div[jsname='rymPhb'] > div")
    for i in assign:
        #WebDriverWait(driver, timeout = 5).until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR, "div[jsname='rymPhb']")))
        driver.execute_script("arguments[0].click();", total[i[0]])
        #total[i[0]].click()
        time.sleep(3)
        assignment = BeautifulSoup(driver.page_source, "lxml")
        WebDriverWait(driver, timeout=6).until(
            expected_conditions.visibility_of(
                driver.find_elements_by_class_name("W4hhKd")[-1]))
        details = assignment.find_all(name="div",
                                      attrs={"class": "W4hhKd"
                                             })[-1].contents  #make DOM visible
        i.append(details[1].string)  #due date
        if i[-1] is None:
            i[-1] = "No due date"
        #i.append(details[0].contents[0].contents[0].string) #max marks
        if len(details[0].contents) == 0:
            i.append("No marks mentioned")
            i.append("No marks received")
        else:
            temp = details[0].contents[0].contents[0].contents
            if len(temp) > 1:
                i.append(temp[1].string.split()[-1])
                i.append(temp[1].string.split()[0])
            else:
                i.append(temp[0])
                i.append("No marks received")
        details = assignment.find_all(name="aside", attrs={
            "class": "asCVDb"
        })[-1].contents[0].contents[0].contents[1].contents[0]
        if details.contents[0].string[0] == 'A':
            i.append(details.contents[0].string + " (Not submitted)")
        else:
            i.append(details.contents[0].string)
        i[0] = driver.current_url
        driver.find_element_by_tag_name("nav").find_element_by_tag_name(
            "div").find_element_by_tag_name("div").find_element_by_tag_name(
                "div").find_element_by_tag_name("h1").find_element_by_tag_name(
                    "a").click()
        time.sleep(2)

    for i in material:
        total[i[0]].click()
        time.sleep(2)
        i[0] = driver.current_url
        driver.find_element_by_tag_name("nav").find_element_by_tag_name(
            "div").find_element_by_tag_name("div").find_element_by_tag_name(
                "div").find_element_by_tag_name("h1").find_element_by_tag_name(
                    "a").click()
        time.sleep(2)
    return assign, material