Beispiel #1
0
def expandVehicleInfoIdirect(driver):
    # sleep for 7-15 seconds to allow the browser to populate data, and fill the div with desired results.
    # expandPath = "//div[@class='visible-md visible-lg right-expand-all']"
    # firefox
    print("Waiting to populate data..")
    print()

    # sleep(SLEEP_TIME)  # Allow for the loader image to fade out in the browser
    isLoaderPresent = False
    # while not isLoaderPresent:
    isLoaderPresent = waitLoader(driver)

    if isLoaderPresent:
        hasExpanded = False
        print("Loader gone!")
        print()
        # startExpand, endExpand = time(), time()
        while not hasExpanded:
            # check if No search results exist.
            if hasNoResults(driver):
                print("No Search results triggered in search.")
                break
            hasExpanded = expandButton(driver)

    else:
        print("Sorry. Page is still loading..")
Beispiel #2
0
def searchFunc(driver, chassisNum=""):
    '''
    One role: Clicks the search button
    '''
    sleep(10)    # delay for 3 seconds to load more info

    try:
        searchPath = "//button[@class='btn btn-primary btn-search search']"
        searchButton = WebDriverWait(driver, SLEEP_TIME).until(
            EC.presence_of_element_located((By.XPATH, searchPath)))
        while searchButton:
            searchButton.click()
            searchButton = driver.find_element_by_xpath(searchPath)
        print("Search button clicked!")

    except Exception as e:
        print(f"Search function failed..[{e}]")

    sleep(10)  # regular value is 3
    # check if there are no results
    # noResultsPath = "div.no-result-message "
    # noResultsCheck = True if driver.find_element_by_css_selector(
    #     noResultsPath).get_attribute("style") == "display: none;" else calibrateSearch(driver)
    noResultsCheck = calibrateSearch(
        driver) if hasNoResults(driver) else True
    print(noResultsCheck)
Beispiel #3
0
def searchFunc(driver, chassisNum=""):
    '''
    One role: Clicks the search button
    '''
    sleep(5)  # delay for 3 seconds to load more info

    # ibcTextBoxPath = "input.form-control.IDVehicle.ibcnumber.isnumber"
    # ibcTextBox = driver.find_element_by_css_selector(ibcTextBoxPath)
    ibcTextBoxPath = "//div[@class='form-adjust width-61per']//input[@name='idvehicle']"
    ibcTextBox = driver.find_element_by_xpath(ibcTextBoxPath)
    ibcTextBox.clear()

    if chassisNum:
        ibcTextBox.send_keys(chassisNum)

    # WebDriverWait(driver, EXPAND_WAIT_TIME).until(EC.presence_of_element_located((By.XPATH, expandPath)))
    try:
        searchPath = "//button[@class='btn btn-primary btn-search search']"
        # searchButton = driver.find_element_by_xpath(searchPath)
        searchButton = WebDriverWait(driver, SLEEP_TIME).until(
            EC.presence_of_element_located((By.XPATH, searchPath)))
        searchButton.click()

    except Exception as e:
        print(f"Search function failed..[{e}]")

    sleep(10)  # regular value is 3
    # check if there are no results
    # noResultsPath = "div.no-result-message "
    # noResultsCheck = True if driver.find_element_by_css_selector(
    #     noResultsPath).get_attribute("style") == "display: none;" else calibrateSearch(driver)
    noResultsCheck = calibrateSearch(driver) if hasNoResults(driver) else True
    print(noResultsCheck)
Beispiel #4
0
def nextResults(webdriver):
    '''
    #1  Get current page number
    #2  Get Next page number reference
    '''
    import os
    getActiveLink = "//ul[@class='pagination margin-top-bottom-none']//li[@class='active']"
    getNextLink = "/following-sibling::li[1]//a"

    infoList = []
    # addInfoList = []

    startDC = time()
    isEnd = False
    createDirectory()

    auctionHouseName = ""

    while not isEnd:
        print("Incur python to sleep..")

        sleep(SLEEP_TIME)

        expandVehicleInfoIdirect(webdriver)

        results = hasNoResults(webdriver)

        if not auctionHouseName:
            auctionHouseName = getAuctionHouse(webdriver)

        if results:
            print("No results displayed..")
            print(f"Data collection for [{auctionHouseName}]: incomplete")
            back_to_search(webdriver)
            isEnd = True
            break

        if time() - startDC >= 240:
            print("DC reached 4 minute limit")
            back_to_search(webdriver)
            break

        startRetrieve = time()
        # infoList.extend(retrieveInfoUpd(webdriver))
        retrievedInfo = retrieveAllInfo(webdriver)
        infoList.extend(retrievedInfo)
        print(retrievedInfo)
        # addInfoList.extend(retrieveInfoDetail(webdriver))
        endRetrieve = time()

        activePage = WebDriverWait(webdriver, WAIT_TIME).until(
            EC.presence_of_element_located((By.XPATH, getActiveLink)))
        nextPage = WebDriverWait(webdriver, WAIT_TIME).until(
            EC.presence_of_element_located(
                (By.XPATH, f"{getActiveLink}/{getNextLink}")))

        print(f"Checking [Page {activePage.text}]..")

        if nextPage.text == "»":
            isEnd = True
            print("Traverse reached last page..")
            print(f"Data collection of [{auctionHouseName}]: completed")
            print()
        else:
            print(
                f"Finished checking [{auctionHouseName}, Page {activePage.text}] in {(endRetrieve-startRetrieve):.1f} seconds."
            )
            print()
            print(f"Next is [Page {nextPage.text}]..")
            try:
                nextPage.click()
            except Exception as e:
                print(f"Error: {e}")
                print(f"No Next page..")
                back_to_search(webdriver)
                break
    else:
        print("Traverse has been stopped..")
        back_to_search(webdriver)
        print()

    endDC = time()

    timeDC = endDC - startDC
    print(f"Finished collecting data in {convert_time(timeDC)} seconds.")

    print(f"Will now check for errors..")
    print()
    startEC = time()
    # checkErrorList = errorCheckUpd(infoList)
    # checkErrorList = errorCheck_ibc_shuppin(infoList)
    # checkErrorList = errorCheckMoreInfo(infoList, addInfoList)
    checkErrorList = dataVerification(infoList)

    # populate_errors = dictErrors(checkErrorList[1])
    populate_errors = dictErrors_shuppin(checkErrorList)
    # print(populate_errors)
    print("----------------------------------------------------------")
    printErrors(populate_errors)
    endEC = time()
    timeEC = endEC - startEC
    # printToFile((timeDC, timeEC),
    #             auctionHouseName, populate_errors)
    printToFile_shuppin((timeDC, timeEC), auctionHouseName, populate_errors)

    print(f"Error checking done in {convert_time(timeEC)} seconds.")