コード例 #1
0
class HeaderText(unittest.TestCase):
    def setUp(self):
        options = EdgeOptions()
        options.use_chromium = True
        options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe"
        dir = os.path.dirname(os.path.realpath(__file__))
        edge_driver_path = dir + "\\edgedriver_win64\\msedgedriver.exe"
        self.driver = Edge(options=options, executable_path=edge_driver_path)
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()
        self.driver.get("http://localhost:4200")

    def test_HeaderText(self):
        headerText = self.driver.find_element_by_css_selector("h1").get_attribute("innerText")
        self.assertEqual("todos", headerText)

    def tearDown(self):
        self.driver.quit()
コード例 #2
0
class ReservationEngine:
    def __init__(self, email, password, headless=True):
        self.email = email
        self.password = password
        self.available = False
        self.booked = False
        self.reservations_left = False
        options = EdgeOptions()
        options.add_argument("--log-level=3")
        options.use_chromium = True
        if headless:
            options.add_argument("headless")
        self.driver = Edge(options=options)
        print("Starting web driver...")

    def remove_overlay(self):
        #get rid of cc overlay
        buttons = self.driver.find_elements_by_css_selector("a.cc-btn")
        while any(map(lambda x: x.size["height"] != 0, buttons)):
            for button in buttons:
                try:
                    button.click()
                except:
                    pass
            buttons = self.driver.find_elements_by_css_selector("a.cc-btn")

    def login(self):
        #login
        print("Logging in")
        self.driver.get(
            "https://account.ikonpass.com/en/login?redirect_uri=/en/myaccount/add-reservations/"
        )
        self.remove_overlay()
        email_box = self.driver.find_element_by_css_selector("input#email")
        email_box.send_keys(self.email)
        password_box = self.driver.find_element_by_css_selector(
            "input#sign-in-password")
        password_box.send_keys(self.password)
        submit = self.driver.find_element_by_css_selector("button.submit")
        submit.click()
        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, 'input.react-autosuggest__input')))
        print("Logged in")

    def refresh(self):
        self.driver.refresh()

    def find_date(self, date, resort):
        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, 'input.react-autosuggest__input')))
        self.remove_overlay()
        #select resort
        search = self.driver.find_element_by_css_selector(
            "input.react-autosuggest__input")
        search.send_keys(resort)
        button = self.driver.find_element_by_css_selector(
            "li#react-autowhatever-resort-picker-section-1-item-0")
        button.click()
        button = self.driver.find_element_by_xpath(
            "//span[contains(text(), 'Continue')]")
        button.click()

        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, 'div.DayPicker-wrapper')))
        self.remove_overlay()

        #select date
        datepicker = self.driver.find_element_by_css_selector(
            "div.DayPicker-wrapper")
        month_selected = False
        while not month_selected:
            month_text = calendar.month_name[date.month]
            month = datepicker.find_elements_by_xpath(
                "//span[contains(text(), " + "'" + month_text + "')]")
            if len(month) > 0:
                month_selected = True
            else:
                button = datepicker.find_element_by_class_name(
                    "icon-chevron-right")
                button.click()

        day = datepicker.find_element_by_xpath("//div[@aria-label='" +
                                               date.strftime("%a %b %d %Y") +
                                               "']")
        day.click()
        day_classes = day.get_attribute(name="class")

        self.available = "past" not in day_classes and "unavailable" not in day_classes
        self.booked = "confirmed" in day_classes
        div = self.driver.find_elements_by_xpath(
            "//div[contains(text(), 'Reservation Limit Reached')]")
        self.reservations_left = len(div) == 0
        print("Date Selected: " + date.strftime("%m/%d/%Y"))

    def reserve(self):
        #confirm reservation if available
        if self.available and not self.booked and self.reservations_left:
            self.remove_overlay()
            button = self.driver.find_element_by_xpath(
                "//span[contains(text(), 'Save')]")
            button.click()
            button = self.driver.find_element_by_xpath(
                "//span[contains(text(), 'Continue to Confirm')]")
            button.click()

            WebDriverWait(self.driver, 10).until(
                EC.presence_of_element_located(
                    (By.XPATH, "//input[@type='checkbox']")))
            button = self.driver.find_element_by_xpath(
                "//input[@type='checkbox']")
            button.click()
            WebDriverWait(self.driver, 10).until(
                EC.presence_of_element_located(
                    (By.XPATH,
                     "//span[contains(text(), 'Confirm Reservations')]")))
            button = self.driver.find_element_by_xpath(
                "//span[contains(text(), 'Confirm Reservations')]")
            button.click()
            self.booked = True
            print("Booked")
        return self.booked

    def log_results(self, log_file_name):
        #log
        with open(log_file_name, "a") as f:
            f.write(datetime.now().strftime("%m/%d/%Y, %H:%M:%S"))
            f.write(": Available - %r, Booked - %r, Reservations Left- %r" %
                    (self.available, self.booked, self.reservations_left))
            f.write("\n")

    def close_driver(self):
        self.driver.close()
コード例 #3
0
def chooseAccount():
    with open('data.txt') as json_file:
        data = json.load(json_file)

    userInfo ='account: ' + data['username']
    print(userInfo) 
    
    userName = data['username']
    passWord = data['password']
    print("link:")
    link = input()
    print("number of photos: ")
    amount = input()

    # format text and amount
    amount = int(amount)

    # auto login
    options = EdgeOptions()
    options.use_chromium = True
    options.add_argument('headless')
    driver = Edge('msedgedriver', options = options)
    driver.get(link)
    time.sleep(2)
    userForm = driver.find_element_by_css_selector("input[name='username']")
    passForm = driver.find_element_by_css_selector("input[name='password']")
    userForm.send_keys(userName)
    passForm.send_keys(passWord)
    driver.find_element_by_css_selector("button[type='submit']").click()
    time.sleep(3)
    driver.execute_script("document.querySelector('.sqdOP.yWX7d.y3zKF').click()")

    # get link image to list
    time.sleep(2)
    if amount > 1: 
        spriteBtn = driver.find_element_by_css_selector(".coreSpriteRightChevron")
    list_link = []
    def get_url1():
        list_element = driver.find_elements_by_css_selector("img[style='object-fit: cover;']")
        for image in list_element[:1]:
            src = image.get_attribute("src")
            list_link.append(src)
    def get_url2():
        list_element = driver.find_elements_by_css_selector("img[style='object-fit: cover;']")
        list_element.pop(0)
        for image in list_element[:1]:
            src = image.get_attribute("src")
            list_link.append(src)

    for x in range(0, amount+1):
        if (len(list_link) > 0):
            get_url2()
        else:
            get_url1()
        if len(list_link) == amount:
            break
        elif spriteBtn:
            spriteBtn.click()
        else:
            break
        time.sleep(0.5)

    # check old image folder exist
    if (os.path.isdir("./image")): 
        rmtree("./image")

    # create new image folder
    folderPath = os.getcwd()
    folderPath += '\image'
    os.mkdir(folderPath)

    # clear screen
    clear = lambda: os.system('cls')
    clear()

    for i in tqdm(range(100)):
        pass

    print("\nnumber of photos:", len(list_link))

    pos = 0
    for href in list_link:
        print(pos+1, "DONE")
        imagePathResult = "./image/image_" + str(pos) + ".png"
        try:
            downloadFile(href)
            copy("./image/image.png", imagePathResult)
        except:
            print("error at %s" %pos+1)
        pos += 1
    os.remove("./image/image.png")

    resultPath = os.getcwd()
    resultPath = resultPath + '\image'
    os.startfile(resultPath)
    
    driver.close()
    chooseMenu()
    if (os.path.isfile(path)):
        key = 2
    else:
        key = 1
    menu(key)
コード例 #4
0
     )))
 button.click()
 print("Test started")
 delay = 350  # seconds
 try:
     WebDriverWait(browser, delay).until(
         EC.presence_of_element_located((
             By.CSS_SELECTOR,
             '#testresult-detail > tbody > tr:nth-child(1) > td:nth-child(2) > span'
         )))
     print("Page is ready!")
     print(browser.current_url)
     # save results as csv
     #DL-speed
     downspeed = browser.find_element_by_css_selector(
         '#verlauf-detail > tbody > tr:nth-child(1) > td:nth-child(3)'
     ).text
     #UL speed
     upspeed = browser.find_element_by_css_selector(
         '#verlauf-detail > tbody > tr:nth-child(2) > td:nth-child(3)'
     ).text
     #Ping
     ping = browser.find_element_by_css_selector(
         '#verlauf-detail > tbody > tr:nth-child(3) > td:nth-child(3)'
     ).text
     #timestamp
     timestamp = browser.find_element_by_css_selector(
         '#testresult-detail > tbody > tr:nth-child(1) > td:nth-child(2) > span'
     ).text
     print("DL: " + downspeed + " ; UL: " + upspeed + " ; ping: " +
           ping)
コード例 #5
0
if (card):
    WebDriverWait(driver, 10)\
        .until(EC.element_to_be_clickable((By.XPATH,
                                           "/html/body/div/div/div[1]/div[1]"))).click()

#INFO
WebDriverWait(driver, 10)\
    .until(EC.element_to_be_clickable((By.XPATH,
                                       '/html/body/div/div/div[1]/div[1]/div')))

info_clima = driver.find_element_by_xpath(
    '/html/body/div/div[5]/div[1]/div[1]')
info_clima = info_clima.text

titulo = driver.find_element_by_css_selector('p.module-title')
titulo = titulo.text
#print(titulo)

#SEPARAR
datos_semana = info_clima.split(titulo)[1].split('\n')[1:36]

dia = list()
fecha = list()
grados = list()
estado = list()
humedad = list()

for i in range(0, len(datos_semana), 5):
    dia.append(datos_semana[i])
    fecha.append((datos_semana[i + 1]))
コード例 #6
0
    def info(self):
        options = EdgeOptions()
        options.use_chromium = True
        #options.add_argument('--start-maximized')
        options.add_argument('--disable-extensions')
        driver_path = 'Driver\\msedgedriver.exe'

        #Opciones de navegacion
        driver = Edge(executable_path=driver_path, options=options)

        #inicializamos el navegador
        driver.get('https://www.accuweather.com/')
        Departamento = "Paysandú"

        #COOKIES
        WebDriverWait(driver, 10)\
            .until(EC.element_to_be_clickable((By.XPATH,
                                               '/html/body/div/div[9]/div/div')))\
            .click()

        #BUSCADOR
        WebDriverWait(driver, 10)\
            .until(EC.element_to_be_clickable((By.XPATH,
                                               '/html/body/div/div[1]/div[2]/div[1]/form/input')))\
            .send_keys(Departamento)

        #CIUDAD
        WebDriverWait(driver, 10)\
            .until(EC.element_to_be_clickable((By.XPATH,
                                               '/html/body/div/div[1]/div[2]/div[2]/div[2]/div')))\
            .click()

        #DIAS
        WebDriverWait(driver, 10)\
            .until(EC.element_to_be_clickable((By.XPATH,
                                               '/html/body/div/div[3]/div/div[3]/a[3]')))\
            .click()

        card = WebDriverWait(driver, 20)\
            .until(EC.frame_to_be_available_and_switch_to_it((By.NAME,
                                                              "google_ads_iframe_/6581/web/sam/interstitial/weather/local_home_0")))

        if (card):
            WebDriverWait(driver, 10)\
                .until(EC.element_to_be_clickable((By.XPATH,
                                                   "/html/body/div/div/div[1]/div[1]"))).click()

        #INFO
        WebDriverWait(driver, 10)\
            .until(EC.element_to_be_clickable((By.XPATH,
                                               '/html/body/div/div/div[1]/div[1]/div')))

        info_clima = driver.find_element_by_xpath(
            '/html/body/div/div[5]/div[1]/div[1]')
        info_clima = info_clima.text

        titulo = driver.find_element_by_css_selector('p.module-title')
        titulo = titulo.text
        #print(titulo)

        #SEPARAR
        datos_semana = info_clima.split(titulo)[1].split('\n')[1:36]

        driver.quit()

        return datos_semana
コード例 #7
0
ファイル: test.py プロジェクト: chefchaouen/typy
def main():
    try:
        print("ウェブドライバーを立ち上げています・・・")
        port = str(args.port[0])
        load_delay_time = args.load_delay_time[0]
        options = EdgeOptions()
        options.use_chromium = True
        driver = Edge(options=options)
        driver.maximize_window()

        if len(port) != 4:
            print("入力した番号は4桁ではないです。4桁のポート番号を記入してください。")
            quit()

        print("ページを開いています・・・")
        driver.get(f"http://127.0.0.1:{port}")
        print(f"ページの読み込みのため{str(load_delay_time)}秒待機します・・・")

        for i in range(load_delay_time, 0, -1):
            time.sleep(1)
            print(f"終わるまで{i}秒")

        print("Interactive Pythonコンソールを立ち上げています・・・")

        soup = BeautifulSoup(driver.page_source, features="lxml")
        #Define web elements to be tested as dictionary where element ids are the keys.
        test_element_ids = {
            "dtFilter": {
                "tag":
                "select",
                "click_el_xpath":
                "/html/body/div/div[1]/div[2]/div/div/div[1]/div/div/div[1]/div[1]/div/div/div"
            },
            "maxAmount": {
                "tag": "input",
            },
            "maxSigma": {
                "tag": "input",
            },
            "pl": {
                "tag":
                "select",
                "click_el_xpath":
                "/html/body/div/div[1]/div[2]/div/div/div[1]/div/div/div[1]/div[5]/div/div/div"
            },
            "reason": {
                "tag":
                "select",
                "click_el_xpath":
                "/html/body/div/div[1]/div[2]/div/div/div[1]/div/div/div[1]/div[6]/div/div/div/div[1]"
            }
        }
        for test_el_id in test_element_ids:
            test_el = test_element_ids[test_el_id]
            if test_el["tag"] == "select":
                el = driver.find_element_by_xpath(test_el["click_el_xpath"])
                el.click()
                soup = BeautifulSoup(driver.page_source, features="lxml")
                select_items = [
                    tag.text for tag in soup.find(
                        id=test_el_id).find_next_sibling().select("div.option")
                ]
                print(f"number of items in select box: {len(select_items)}")
                for select_item in select_items:
                    click_el = driver.find_element_by_css_selector(
                        f"[data-value='{select_item}']")
                    el.click()
                    click_el.click()
                    time.sleep(5)
            elif test_el["tag"] == "input":
                test_round = 1
                while test_round < 6:
                    test_input_number = int(random.random() * random.choice([
                        10, 100, 1000, 10000, 100000, 1000000, 10000000,
                        10000000, 100000000
                    ]))
                    el = driver.find_element_by_id(test_el_id)
                    el.clear()
                    el.click()
                    el.send_keys(test_input_number)
                    time.sleep(5)
                    test_round += 1
                el.clear()
                el.send_keys(0)
    except Exception as e:
        print(
            f"(EXCEPT) An error occurred: {str(e)} Attempting to enter debug mode at point of error."
        )
        embed()
    finally:
        print("プログラムが正常終了しました。ウェブドライバーを終了します。お疲れ様でした。")
        embed()
        driver.close()