Exemplo n.º 1
0
    def validate_elements(val_brutebot):

        global val2_output

        tmp_driver = Browser(showWindow=False, proxy=brutebot.proxy)
        tmp_driver.go_to(val_brutebot.target)
        time.sleep(val_brutebot.time_in_seconds)

        x = tmp_driver.exists(val_brutebot.uid, css_selector=str('input[type=text][id="{}"]').format(brutebot.uid))
        y = tmp_driver.exists(val_brutebot.pid, css_selector=str('input[type=password][id="{}"]').format(brutebot.pid))
        z = tmp_driver.exists(val_brutebot.button_name,
                              css_selector=str('button[type=submit][value="{}"]'
                                               or 'input[type=submit][value="{}"]').format(brutebot.button_name))

        if x and y and z:
            time.sleep(val_brutebot.time_in_seconds)
            tmp_driver.close_current_tab()
            val2_output = True
            print_green(f"[!] The specified URL and the login page elements seem OK.\n")
            sys.exit()
        else:
            print_red(
                '[!] Error: The specified URL / login page elements could not be found. Please check & try again.\n\n'
                '[!] Exiting program!\n')
            val2_output = False
            sys.exit()
Exemplo n.º 2
0
def go_to_oracle_page(links=(), show_window=False, use_obi=False):
    """Open a webbot instance and log in to Oracle, opening the link(s) specified therein.
    links can be a string or a list of strings.
    Returns the webbot instance, so you can do more things with it."""
    web = Browser(showWindow=show_window)
    obi_url = 'https://obi.ssc.rcuk.ac.uk/analytics/saw.dll?dashboard&PortalPath=%2Fshared%2FSTFC%20Shared%2F_portal%2FSTFC%20Projects'
    ebs_url = 'https://ebs.ssc.rcuk.ac.uk/OA_HTML/AppsLogin'
    for _ in range(2):
        # first try without VPN connection
        web.go_to(obi_url if use_obi else ebs_url)
        if web.exists('Enter your Single Sign-On credentials below'):
            break
        # failed? try connecting to VPN
        subprocess.call('RASDial "RAL VPN"')
    else:
        raise RuntimeError('Failed to load Oracle login page')
    web.type(username, 'username')
    web.type(password, 'password')
    web.click('Login')

    time.sleep(2)
    if isinstance(links, str):
        links = [
            links,
        ]
    for link in links:
        web.click(link)
        time.sleep(2)
    return web
Exemplo n.º 3
0
def _manager_ui_login(url, user, realm, delay=30):
    if config.DRY_RUN:
        return Browser(showWindow=False)
    browser_options = (['ignore-certificate-errors']
                       if url == 'localhost' else [])
    driver = Browser(showWindow=not config.QUIET,
                     browser_options=browser_options)
    start = time.time()
    end = start
    driver.go_to(f'https://{url}/manager/?realm={realm}')
    while not driver.exists('LOG IN') and not driver.exists('SIGN IN'):
        if not config.QUIET:
            print('+', end='', flush=True)
        time.sleep(0.2)
        end = time.time()
        if end - start > delay:
            raise Exception(f'{url}: no login page after {delay}s')
    driver.type(user, into='username')
    driver.type(config.get_password(url, user), into='password')
    driver.click('SIGN IN')
    driver.click('LOG IN')
    end = time.time()
    print(f'{url} login time\t{end-start:.2f}s')
    return driver
Exemplo n.º 4
0
 def main(self):
     #print("time:", time)
     #file=open('Online.txt','a')
     #file.write('testing')
     #file.close()
     #file=open('Online.txt','a')
     #file.write('testing2'+str(time))
     #file.close()
     web = Browser()
     web.go_to("http://web.whatsapp.com/send?phone=918638372098")
     time.sleep(10)
     for i in range(0, 100):
         for i in range(0, len(self.email)):
             #self.hide()
             web.go_to("http://web.whatsapp.com/send?phone=91" +
                       self.email[i])
             time.sleep(10)
             if web.exists(text='online'):
                 now = datetime.now()
                 ttime = now.strftime("%H:%M:%S")
                 file = open(self.email[i] + '.txt', 'a')
                 file.write('\n online at' + str(ttime))
                 file.close()
     time.sleep(1)
Exemplo n.º 5
0
    if web.exists('Home') == True:
        web.click(classname='Home')  #

    print('sleep')
    time.sleep(random.randint(1, 30))  #chargement de la page


web = Browser("--disable-dev-shm-usage")
web.maximize_window()

try:
    login(web)
except:
    print('error loggin')

if web.exists(classname='view-navbar-currency-coins'
              ) == True:  #on recupere les coins
    coins = web.driver.find_element_by_class_name(
        'view-navbar-currency-coins').text
    a_coins = int((coins.replace(',', '')).replace(' ', ''))
    print('on commence avec : ', a_coins)
else:
    a_coins = 1001

try:
    sell_players(web)
except:
    print('erreur lors du sell')

try:
    while a_coins > 1000:
        try:
Exemplo n.º 6
0
def main():
	while True:
		web = Browser(showWindow = pencere_acilsin_mi)
		try:
			m1 = random.randint(20,500)
			m2 = random.randint(-200,700)
			m3 = random.randint(40,900)
			web.set_page_load_timeout(60)
			web.go_to(site)
			if web.exists(kelime):
				sleep(random.randint(20,50))
				print("anasayfa")
				web.scrolly(m1) 
				web.scrolly(m2) 
				web.scrolly(m3)
				try:
					a = []
					a = web.find_elements(tag='a')
					sec = random.choice(a)
					sec.click()
					print(web.get_title())
					acik = web.get_total_tabs()
					if acik>1:
						web.switch_to_tab(2)
					sleep(random.randint(20,50))
					web.scrolly(m1) 
					web.scrolly(m2) 
					web.scrolly(m3)
					try:
						a = []
						a = web.find_elements(tag='a')
						sec = random.choice(a)
						sec.click()
						acik1 = web.get_total_tabs()
						if acik1>1:
							web.switch_to_tab(acik1)
						sleep(random.randint(20,50))
						print(web.get_title())
						web.scrolly(m1) 
						web.scrolly(m2) 
						web.scrolly(m3)
						try:
							a = []
							a = web.find_elements(tag='a')
							sec = random.choice(a)
							sec.click()
							acik2 = web.get_total_tabs()
							if acik2>1:
								web.switch_to_tab(acik2)
							sleep(random.randint(20,50))
							print(web.get_title())
							web.scrolly(m1) 
							web.scrolly(m2) 
							web.scrolly(m3)
							try:
								a = []
								a = web.find_elements(tag='a')
								sec = random.choice(a)
								sec.click()
								acik3 = web.get_total_tabs()
								if acik3>1:
									web.switch_to_tab(acik3)
								sleep(random.randint(20,50))
								print(web.get_title())
								web.scrolly(m1) 
								web.scrolly(m2) 
								web.scrolly(m3)
								try:
									a = []
									a = web.find_elements(tag='a')
									sec = random.choice(a)
									sec.click()
									acik4 = web.get_total_tabs()
									if acik4>1:
										web.switch_to_tab(acik4)
									sleep(random.randint(20,50))
									print(web.get_title())
									web.scrolly(m1) 
									web.scrolly(m2) 
									web.scrolly(m3)
									try:
										a = []
										a = web.find_elements(tag='a')
										sec = random.choice(a)
										sec.click()
										acik5 = web.get_total_tabs()
										if acik5>1:
											web.switch_to_tab(acik5)
										sleep(random.randint(20,50))
										print(web.get_title())
										web.scrolly(m1) 
										web.scrolly(m2) 
										web.scrolly(m3)
										try:
											a = []
											a = web.find_elements(tag='a')
											sec = random.choice(a)
											sec.click()
											acik6 = web.get_total_tabs()
											if acik6>1:
												web.switch_to_tab(acik6)
											sleep(random.randint(20,50))
											print(web.get_title())
											web.scrolly(m1) 
											web.scrolly(m2) 
											web.scrolly(m3)
											try:
												a = []
												a = web.find_elements(tag='a')
												sec = random.choice(a)
												sec.click()
												acik7 = web.get_total_tabs()
												if acik7>1:
													web.switch_to_tab(acik7)
												sleep(random.randint(20,50))
												print(web.get_title())
												web.scrolly(m1) 
												web.scrolly(m2) 
												web.scrolly(m3)
												web.quit()
											except:
												web.quit()
										except:
											web.quit()
									except:
										web.quit()
								except:
									web.quit()
							except:
								web.quit()
						except:
							web.quit()
					except:
						web.quit()	
				except:
					web.quit()	
			else:
				web.quit()
		except:
			web.quit()
Exemplo n.º 7
0
#!/usr/bin/python3
from webbot import Browser
web = Browser()
web.go_to('https://unidemo.webex.com/meet/emarcelobarreto')
#web.go_to('https://unidemo.webex.com/webappng/sites/unidemo/dashboard/pmr/huaman1942?siteurl=unidemo')
web.click("Entrar a la reunión")
#web.go_to('https://unidemo.webex.com/webappng/sites/unidemo/meeting/download/ddc993d54459e2515c68cceb6856bfec?launchApp=true')
for i in range(0,2):
    if(web.exists("IDONTKNOW")):
        web.click("IDK")

web.press(web.Key.ENTER)
for i in range(0,2):
    print(i)
    if(web.exists("IDONTKNOW")):
        web.click("IDK")
web.type('Josue Huaroto\[email protected]')
#for i in range(0,1):
#    if(web.exists("IDONTKNOW")):
#        web.click("IDK")
web.press(web.Key.ENTER)
for i in range(0,7):
    print(i)
    if(web.exists('Saltear')):
        web.click('Saltear')
    else:
        web.press(web.Key.ESCAPE)

for i in range(0,6):
    if(web.exists('Saltear')):
        web.click('Saltear')
Exemplo n.º 8
0
#!/usr/bin/python3
from webbot import Browser
web = Browser()
web.go_to('http://www.earpunifim.com/')
web.type("YOUR_CODE", into="Usuario UNI")
web.type("YOUR_PASSWORD", into="Password")
web.press(web.Key.ENTER)
web.click("Mi Asistencia", id="asistencia_alumno_utfim")
cont = 1
while cont < 10:
    if web.exists(
            css_selector=
            ".mdl-button.mdl-js-button.mdl-button--raised.mdl-js-ripple-effect.btnMarcar.mdl-button--colored"
    ):
        web.click(
            css_selector=
            ".mdl-button.mdl-js-button.mdl-button--raised.mdl-js-ripple-effect.btnMarcar.mdl-button--colored",
            number=cont)
        print("YES :)")
        web.go_to('http://www.earpunifim.com/departamento/asistencia/alumno')
        cont += 1
web.quit()
Exemplo n.º 9
0
def action(id, pw, booking_id):
    driver = Browser()
    driver.go_to(constants.URL)
    time.sleep(3)
    driver.click(tag='a', text='Log in')
    print('>>> Logging in')
    time.sleep(3)
    driver.type(id, into='Enter Member ID, barcode or email address')
    driver.type(pw, into='Enter password')
    driver.click(xpath=constants.LOGIN_BUTTON_PATH)
    time.sleep(10)

    if driver.exists(
            tag='span',
            text='Email address or Barcode or Member ID not recognized'):
        print(
            'ERROR: Unable to login (Email address or Barcode or Member ID not recognized)'
        )
        return

    location = driver.find_elements(
        id='js-search-location-default-club')[0].get_attribute('innerText')
    time.sleep(3)

    # Switch location
    if location != constants.LOCATION:
        print('>>> Switching locations')
        driver.click(tag='a', id='js-search-filter-change')
        driver.click(tag='section', id='section_clubs')
        # Switch to correct location
        driver.execute_script(
            'document.querySelector(\'[data-clubnumber="243"]\').click()')
        driver.click(id='js-filter-location-button-apply')
        time.sleep(3)

    print('>>> Booking...')
    driver.click(tag='label', classname='c-filter__label', text='Co-ed')
    time.sleep(3)
    driver.click(classname='js-unordered-list-button-mobile')
    # Select the newest day
    driver.click(tag='li', css_selector='[data-day="day-number-7"]')

    if driver.exists(tag='h5',
                     text='Open Workout',
                     xpath=constants.OPEN_WORKOUT_PATH):
        booking_id = booking_id + 1

    driver.click(xpath=constants.LAST_BOOKING_OPTIONS.replace(
        'li', 'li[' + str(booking_id) + ']'))

    if driver.errors:
        print('ERROR: Fully booked')
        return

    time.sleep(2)
    # Scroll to bottom of modal
    driver.execute_script('var element = document.getElementById("js-workout-booking-agreement-input"); ' \
            'element.scrollIntoView()')
    # Agreement
    driver.execute_script(
        'document.getElementById("js-workout-booking-agreement-input").click();'
    )
    time.sleep(2)
    driver.click(text='Confirm')
    print('>>> Booking confirmed')
    time.sleep(2)
    # Close confirmation dialog
    driver.click(xpath=constants.CLOSE_DIALOG_PATH)
    print('>>> Logging out')
    driver.click(tag='a', text='logout')
    print('>>> Finished')
Exemplo n.º 10
0
class TribalClient:
    def __init__(self,
                 session_cookie,
                 world,
                 word_settings: WorldSettings = None):
        self.driver = Browser()
        self.world = world
        self._session_cookie = session_cookie
        self.barbarians = []
        self.available_troops = {key.value: 0 for key in Troops}

    def login(self):
        self.driver.go_to('https://plemiona.pl')
        self.driver.add_cookie({
            'name': 'pl_auth',
            'value': self._session_cookie
        })
        self.driver.refresh()
        self.driver.click(text=str(self.world))
        if self.driver.exists(id='popup_box_daily_bonus'):
            self.driver.click(classname='popup_box_close')

    def get_current_domain(self):
        uri = self.driver.get_current_url()
        parsed_uri = urlparse(uri)
        return f'{parsed_uri.scheme}://{parsed_uri.netloc}'

    def get_outgoings_attacks_from_place(self):
        self.go_to_place()
        outgoings_attacks_box = self.driver.driver.find_element_by_id(
            'commands_outgoings')
        attacked_villages_elements = outgoings_attacks_box.find_elements_by_class_name(
            'quickedit-label')

    @staticmethod
    def _replace_screen_in_url(url, screen_name: str) -> str:
        parsed_url = urlparse(url)
        parsed_query = parse_qs(parsed_url.query)
        parsed_query['screen'] = screen_name
        final_url = parsed_url._replace(
            query=urlencode(parsed_query, doseq=True)).geturl()
        return final_url

    def go_to_place(self):
        if 'screen=place' not in self.driver.get_current_url():
            self.driver.go_to(
                f'{self.get_current_domain()}/game.php?village=62967&screen=place'
            )

    def go_to_train_screen(self):
        if 'screen=train' not in self.driver.get_current_url():
            self.driver.go_to(
                f'{self.get_current_domain()}/game.php?village=62967&screen=train'
            )

    def go_to_main_screen(self):
        if 'screen=main' not in self.driver.get_current_url():
            self.driver.go_to(
                self._replace_screen_in_url(self.driver.get_current_url(),
                                            'main'))

    def slow_type(self, text, *args, **kwargs):
        text_input = self.driver.find_elements(*args, **kwargs)[0]
        text_input.clear()
        for letter in text:
            text_input.send_keys(letter)
            time.sleep(0.020)
            # self.driver.type(letter, *args, clear=False, **kwargs)

    def _extend_viallages_list(self):
        self.driver.driver.find_element_by_css_selector(
            '.village-item.village-more').click()

    def get_nearest_barbarians_villages(self, radius=10):
        # self.go_to_place()
        # self.driver.click(css_selector='input[value="village_name"]')  # nazwa wioski radio button
        self.slow_type('Wioska Barbarzyńska',
                       css_selector='#content_value .target-input-field')
        time.sleep(0.2)
        x = self.driver.driver.find_elements_by_class_name(
            'target-input-field')
        farthest_village_distance = 1
        villages = []
        # time.sleep(0.5)
        while farthest_village_distance < radius:
            time.sleep(0.1)
            villages = self.driver.driver.find_elements_by_css_selector(
                'div.target-select-autocomplete .village-item')[:-1]
            farthest_village_distance = parse_village_html(
                villages[-1]).distance
            self._extend_viallages_list()
        self.barbarians = []
        for village in villages:
            parsed_village = parse_village_html(village)
            if parsed_village.owner == 'Barbarzyńskie':
                self.barbarians.append(parsed_village)

    def get_troop_type_count_from_place(self, troop_type):
        unparsed_number = self.driver.driver.find_element_by_id(
            f'units_entry_all_{troop_type}').text
        return int(unparsed_number[1:-1])

    def get_troop_type_count_available_to_recruit(self, troop_type):
        self.go_to_train_screen()
        available_count_element = self.driver.driver.find_element_by_id(
            f'{troop_type.value}_0_a')
        return int(available_count_element.text[1:-1])

    def get_available_troops(self):
        for troop_type in Troops:
            self.available_troops[
                troop_type.value] = self.get_troop_type_count_from_place(
                    troop_type)
        return self.available_troops

    def get_available_resources(self) -> Resources:
        wood = int(self.driver.driver.find_element_by_id('wood').text)
        stone = int(self.driver.driver.find_element_by_id('stone').text)
        iron = int(self.driver.driver.find_element_by_id('iron').text)
        max_storage = int(
            self.driver.driver.find_element_by_id('storage').text)
        population = int(
            self.driver.driver.find_element_by_css_selector(
                'span#pop_current_label').text)
        max_population = int(
            self.driver.driver.find_element_by_css_selector(
                'span#pop_max_label').text)
        return VillageResources(wood, stone, iron, population, timedelta(0),
                                max_storage, max_population)

    def _fill_troop_form(self, troop_type, value):
        input_text = self.driver.driver.find_element_by_css_selector(
            f'#unit_input_{troop_type}')
        input_text.clear()
        input_text.send_keys(value)

    def fill_recruit_troop_form(self, troop_type, value):
        input_element = self.driver.driver.find_element_by_name(
            troop_type.value)
        input_element.clear()
        input_element.send_keys(str(value))

    def confirm_recruit(self):
        confirm_btn = self.driver.driver.find_element_by_class_name(
            'btn-recruit')
        confirm_btn.click()

    def _fill_target_village_cords(self, cords: Tuple[int, int]):
        target_input = self.driver.driver.find_element_by_class_name(
            'target-input-field')
        target_input.send_keys(f'{cords[0]}{cords[1]}')
        time.sleep(uniform(0.1, 0.2))

    def _confirm_attack(self):
        self.driver.driver.find_element_by_id('target_attack').click()
        time.sleep(uniform(0.1, 0.2))
        self.driver.driver.find_element_by_id('troop_confirm_go').click()

    def send_attack(self, target_cords: Tuple[int, int], troop_config: dict):
        self.go_to_place()
        self._fill_target_village_cords(target_cords)
        for troop_type, troop_count in troop_config.items():
            self._fill_troop_form(troop_type, troop_count)
        self._confirm_attack()

    def send_attack_to_nearest_villages(self,
                                        count=5,
                                        skip=0,
                                        light_chunk_count=5,
                                        axe_chunk_count=1):
        self.go_to_place()
        self.get_available_troops()
        count = light_chunk_count + axe_chunk_count
        light_chunk_size = int(self.available_troops[Troops.LIGHT.value] /
                               light_chunk_count)
        axe_chunk_size = int(self.available_troops[Troops.AXE.value] /
                             axe_chunk_count)

        for village in self.barbarians[skip:skip + count]:
            any_troops = False
            if light_chunk_count and light_chunk_size > 10:
                self._fill_troop_form(Troops.LIGHT, light_chunk_size)
                light_chunk_count -= 1
                any_troops = True
            elif axe_chunk_count and axe_chunk_size > 50:
                self._fill_troop_form(Troops.AXE, axe_chunk_size)
                axe_chunk_count -= 1
                any_troops = True
            if any_troops:
                self._fill_target_village_cords(village.cords)
                time.sleep(0.2)
                self._confirm_attack()
                time.sleep(0.2)

    def _get_build_row(self, building_name):
        return self.driver.driver.find_element_by_css_selector(
            f'tr#main_buildrow_{building_name}')

    def _get_build_orders_rows_for_building(self, building_name: str):
        return self.driver.driver.find_elements_by_class_name(
            f'buildorder_{building_name}')

    def _get_build_queue_rows(self):
        self.go_to_main_screen()
        return self.driver.driver.find_elements_by_css_selector(
            'tbody#buildqueue>tr.nodrag, tbody#buildqueue>.sortable_row')

    def get_build_queue_size(self):
        return len(self._get_build_queue_rows())

    def get_build_end_time(self):
        build_queue_rows = self._get_build_queue_rows()
        end_time = datetime.now()
        for build_row in build_queue_rows:
            time_string = build_row.find_element_by_css_selector('td')
            end_time += TimeHelper.parse_tribal_timedelta_format(time_string)
        return end_time

    def get_building_level(self, building_name) -> int:
        building_row = self._get_build_row(building_name)
        current_level_string = building_row.find_element_by_tag_name(
            'td').find_element_by_tag_name('span').text
        try:
            current_level = int(re.search("\d+", current_level_string).group())
        except AttributeError:
            current_level = 0
        build_order_row_for_building = self._get_build_orders_rows_for_building(
            building_name)
        return current_level + len(build_order_row_for_building)

    def build(self, build_queue: deque):
        for i in range(2 - self.get_build_queue_size()):
            if not build_queue:
                print('Pusta kolejka')
                return
            building_name = build_queue.popleft()
            building_row = self._get_build_row(building_name)
            try:
                build_inactive_displayed = building_row.find_element_by_css_selector(
                    'span.inactive').is_displayed()
            except NoSuchElementException:
                build_inactive_displayed = False
            if build_inactive_displayed:
                print(f"Currently you can't build {building_name}")
                build_queue.appendleft(building_name)
                return
            build_button = building_row.find_element_by_css_selector(
                'td.build_options a.btn-build')
            try:
                build_button.click()
                level = int(re.search(r'\d+', build_button.text).group())
                print(f'Built {building_name} at level {level}')
                time.sleep(0.1)
            except StaleElementReferenceException:
                build_queue.appendleft(building_name)

    def continous_attack(self, light_chunk_size=20):
        self.go_to_place()
        self.get_available_troops()

        while True:
            if self.get_troop_type_count_from_place(
                    Troops.LIGHT) >= light_chunk_size:
                village = random.choice(self.barbarians)
                self._fill_troop_form(Troops.LIGHT, light_chunk_size)
                time.sleep(0.2)
                self._fill_target_village_cords(village.cords)
                time.sleep(0.2)
                self._confirm_attack()
            else:
                time.sleep(0.2)
Exemplo n.º 11
0
class Site(threading.Thread):
    def __init__(self, tid, config_filename, headless=False):
        threading.Thread.__init__(self)
        self.tid = tid
        self.start_time = time()
        self.log = Logger(tid).log
        self.web = Browser(showWindow=headless)
        with open(config_filename) as task_file:
            self.T = load(task_file)
        with open('config.json') as config_file:
            self.C = load(config_file)

    def wait(self, time):
        self.log('sleeping {} second(s)'.format(time))
        sleep(time)

    def login(self):
        self.web.go_to('https://catalog.usmint.gov/account-login')
        self.web.type(self.T["email"], into='Login')
        self.web.type(self.T["password"], into='Password')
        self.web.click('Sign In')

    def get_products(self):
        self.log('getting some products')
        self.web.go_to(self.T["link"])

    def add_to_cart(self):
        self.log('adding product to cart', 'blue')
        self.web.click('Add to Bag')
        # self.wait()

    def checkout(self):
        self.log('checking out')
        while not self.web.exists('Checkout', loose_match=False):
            self.wait(0.02)
        self.web.click('Checkout')
        self.web.click(id="shipping-method")
        self.web.click('Next Day')
        self.wait(0.1)

        # self.web.type(self.T["email"] , into='Login')
        # self.web.type(self.T["password"] , into='Password')
        # self.web.click('Checkout as Registered User')

        self.web.click(id="dwfrm_singleshipping_addressList")
        self.web.click(self.T["address"])
        self.wait(0.2)

        self.web.click(id="dwfrm_billing_paymentMethods_creditCardList")
        self.web.click(self.T["card"])
        self.web.type(self.T["cvv"],
                      id="dwfrm_billing_paymentMethods_creditCard_cvn")
        while not self.web.exists('Continue to Final Review',
                                  loose_match=False):
            self.wait(0.02)
        self.web.click('Continue to Final Review')
        # self.wait()

    def run(self):
        self.login()
        self.get_products()
        self.add_to_cart()
        self.checkout()
        self.wait(30)
        self.log(
            'time to checkout: {} sec'.format(abs(self.start_time - time())),
            'green')
Exemplo n.º 12
0
class Site(threading.Thread):
    def __init__(self, tid, config_filename, headless=False):
        threading.Thread.__init__(self)
        self.tid = tid
        self.start_time = time()
        self.log = Logger(tid).log
        self.web = Browser(showWindow=not headless, incognito=True)
        self.gold_link = 'https://catalog.usmint.gov/basketball-hall-of-fame-2020-uncirculated-silver-dollar-20CD.html?cgid=silver-dollars#start=1'
        self.silver_link = ''

        with open(config_filename) as task_file:
            self.T = load(task_file)

    def wait(self, time):
        self.log('sleeping {} second(s)'.format(time))
        sleep(time)

    def login(self):
        self.web.go_to('https://catalog.usmint.gov/account-login')
        self.web.type(self.T["email"], into='Login')
        self.web.type(self.T["password"], into='Password')
        self.web.click(id="login")

    def get_products(self):
        self.log('getting some products')
        self.web.go_to(self.gold_link)
        day = 4
        hour = 20
        minute = 0
        dt = datetime.datetime(2020, 11, day, hour, minute, 0)
        self.log(f'waiting until {hour}:{minute}')
        pause.until(dt)

    def add_to_cart(self):
        # while self.web.exists(classname="acsClassicInner"):
        #     self.log('survey pop up detected')
        #     self.web.refresh()
        self.log('adding product to cart', 'blue')
        while not self.web.exists('Add to Bag', loose_match=False):
            self.log('waiting for add to bag button to appear')
            self.refresh()
        self.web.click('Add to Bag')

    def checkout(self):
        self.log('checking out')
        self.web.click(classname="mini-cart-link")
        self.web.click(id="shipping-method")
        self.web.click('Next Day')
        self.wait(0.1)

        # self.wait(300)
        self.web.click(id="dwfrm_singleshipping_addressList")
        self.web.click(self.T["address"])
        self.wait(0.8)  #

        self.web.click(id="dwfrm_billing_paymentMethods_creditCardList")
        self.web.click(self.T["card"])
        self.web.type(self.T["cvv"],
                      id="dwfrm_billing_paymentMethods_creditCard_cvn")
        while not self.web.exists(id="checkoutContinuePaymentDelegator",
                                  loose_match=False):
            self.log('waiting for checkout button')
            self.wait(0.01)
        self.web.click(id="checkoutContinuePaymentDelegator")

        ############# self.web.click(id="submitOrderButton") # UNCOMMENT TO PURCHASE

    def run(self):
        self.login()
        self.get_products()
        self.add_to_cart()
        self.checkout()
        # self.wait(3000)
        self.log(
            'time to checkout: {} sec'.format(abs(self.start_time - time())),
            'green')
Exemplo n.º 13
0
URL1 = "https://sslvpn.curtin.edu.au/"
URL2 = "tanjiro.cs.curtin.edu.au"

br = Browser()
br.go_to(URL1)

br.type(person.staffId, id="username")
br.type(person.password, id="password_input")
br.click("Login")

isFound = True
while (isFound):
    if (br.exists(
            id="keepout",
            xpath=
            '/html/body/table/tbody/tr[3]/td/div/table/tbody/tr[2]/td/div/table/tbody/tr[2]/td/input[2]'
    )):
        br.click(
            id="keepout",
            xpath=
            '/html/body/table/tbody/tr[3]/td/div/table/tbody/tr[2]/td/div/table/tbody/tr[2]/td/input[2]'
        )
        isFound = False
        print("Page has loaded")
    else:
        print("Waiting for page to load")

br.type(URL2, id="unicorn_form_url")
br.click(id="go")