def start_and_login(): while True: opts = chromeOpts() opts.add_argument(f"user-agent={ua.random}") prefs = { 'profile.managed_default_content_settings.images': 2 } # Disallow images from loading opts.add_experimental_option("prefs", prefs) driver = helium.start_chrome( "https://www.udemy.com/random_page_that_does_not_exist/", headless=False, options=opts) driver.add_cookie({ 'name': 'client_id', 'value': client_id, 'domain': udemy_domain }) driver.add_cookie({ 'name': 'access_token', 'value': access_token, 'domain': udemy_domain }) helium.go_to("https://www.udemy.com/?persist_locale=&locale=en_US") if 'upgrade-your-browser' in driver.current_url: driver.quit() else: break try: helium.wait_until(helium.Button('Log in').exists, timeout_secs=3.5) helium.kill_browser() raise InvalidCookiesException() except TimeoutException: return driver
def login_connpass(): """connpassにログインする(ユーザー名とパスワードは環境変数を想定)""" go_to("connpass.com/login") write(os.getenv("CONNPASS_USERNAME"), into="ユーザー名") write(os.getenv("CONNPASS_PASSWORD"), into="パスワード") click("ログインする") wait_until(Text("あなたのイベント").exists)
def run_url_catcher(): try: wait_until(fetch_download_url, timeout_secs=15) except TimeoutException as e: print("Failed!") print(e) else: return URL finally: kill_browser() if URL is None: sys.exit(1)
def wait(string=None): if (string in BUTTON): if (string in BUTTON[:6] or string == 'Add an Item'): sleep(1) WebDriverWait(driver,999).until(EC.presence_of_element_located( (By.XPATH, "//body[@class='o_web_client']"))) wait_until(Button(string).exists,999) else: wait_until(Text(string).exists,999)
from contextlib import contextmanager from helium import ( Text, click, go_to, kill_browser, start_firefox, wait_until, write, ) @contextmanager def using_firefox(): start_firefox() try: yield finally: kill_browser() if __name__ == "__main__": with using_firefox(): go_to("connpass.com/login") write(os.getenv("CONNPASS_USERNAME"), into="ユーザー名") write(os.getenv("CONNPASS_PASSWORD"), into="パスワード") click("ログインする") wait_until(Text("あなたのイベント").exists)
def test_wait_until_lambda_with_driver_expires(self): with self.assertRaises(TimeoutException): wait_until(lambda driver: False, timeout_secs=0.1)
def test_wait_until_lambda_expires(self): with self.assertRaises(TimeoutException): wait_until(lambda: False, timeout_secs=1)
def test_wait_until_presence_of_element_located(self): click("Click me!") start_time = time() wait_until(presence_of_element_located((By.ID, "result"))) end_time = time() self.assertGreaterEqual(end_time - start_time, 0.8)
def test_wait_until_text_exists(self): click("Click me!") start_time = time() wait_until(Text("Success!").exists) end_time = time() self.assertGreaterEqual(end_time - start_time, 0.8)
def connect_to_local_runtime(user_choice): try: # import chromedriver_binary if user_choice == "ClointFusion Labs (Public)": colab_url = "https://accounts.google.com/signin/v2/identifier?authuser=0&hl=en&continue=https://colab.research.google.com/github/ClointFusion/ClointFusion/blob/master/ClointFusion_Labs.ipynb" #https://colab.research.google.com/github/ClointFusion/ClointFusion/blob/master/ClointFusion_Labs.ipynb" # colab_url = "https://colab.research.google.com/github/ClointFusion/ClointFusion/blob/master/ClointFusion_Labs.ipynb" # elif user_choice == "ClointFusion Lite (Interns Only)": # #Extract encrypted version of ClointFusion_Lite to a specific folder and in Colab import that folder # colab_url = 'https://accounts.google.com/signin/v2/identifier?authuser=0&hl=en&continue=https://colab.research.google.com/drive/11MvoQfNFXJqlXKcXV1LBVUE98Ks48M_a' elif user_choice == "ClointFusion Starter (Hackathon)": colab_url = 'https://accounts.google.com/signin/v2/identifier?authuser=0&hl=en&continue=https://colab.research.google.com/drive/1G9mh58z8AbWqBit2TC4Wgg6p_eHPvUJB' user_data_path = "C:\\Users\\{}\\AppData\\Local\\Google\\Chrome\\User Data".format(os.getlogin()) modify_file_as_text(user_data_path + '\\Default\\Preferences', 'crashed', 'false') options = Options() options.add_argument("--start-maximized") options.add_experimental_option('excludeSwitches', ['enable-logging']) if os_name == "windows": options.add_argument("user-data-dir=C:\\Users\\{}\\AppData\\Local\\Google\\Chrome\\User Data".format(os.getlogin())) elif os_name == "darwin": options.add_argument("user-data-dir=/Users/{}/Library/Application/Support/Google/Chrome/User Data".format(os.getlogin())) options.add_argument(f"profile-directory=Default") browser_driver = webdriver.Chrome(ChromeDriverManager().install(), options=options) browser.set_driver(browser_driver) browser.go_to(colab_url) chrome = gw.getWindowsWithTitle('Google Chrome')[0] chrome.activate() # pg.doubleClick(pg.size()[0]/2,pg.size()[1]/2) # kb.press_and_release('esc') # kb.press_and_release('esc') try: browser.wait_until(browser.Text("Code").exists,timeout_secs=6) except :#selenium_wrappers.common.exceptions.TimeoutException: try: browser.click(email) except: browser.write(email, into='Email or phone') browser.click('Next') time.sleep(0.5) browser.write(passwd, into='Enter your password') browser.click('Next') time.sleep(0.5) browser.wait_until(browser.Text("Code").exists,timeout_secs=240) # kb.press_and_release('esc') # time.sleep(0.2) # pg.press(ESCAPE) # time.sleep(0.2) # press(ESCAPE) # time.sleep(0.2) if FIRST_TIME: #create short-cut browser.press(browser.CONTROL + 'mh') time.sleep(1) v = S("//input[@id='pref_shortcut_connectLocal']") browser.write('',v) browser.press(browser.CONTROL + '1') time.sleep(0.5) browser.click("SAVE") time.sleep(1) #use short-cut browser.press(browser.CONTROL + '1') time.sleep(1) # pg.alert("HKHR") pg.doubleClick(pg.size()[0]/2,pg.size()[1]/2) time.sleep(1) if FIRST_TIME: # kb.press_and_release('SHIFT+TAB') pg.hotkey('SHIFT', 'TAB') time.sleep(0.5) # kb.press_and_release('SHIFT+TAB') pg.hotkey('SHIFT', 'TAB') time.sleep(0.5) # kb.press_and_release('SHIFT+TAB') pg.hotkey('SHIFT', 'TAB') time.sleep(0.5) pg.write("http://localhost:8888") # kb.write("http://localhost:8888") time.sleep(2) # click("CONNECT") # kb.press_and_release('TAB') pg.hotkey('TAB') time.sleep(0.5) # pg.alert(1) # kb.press_and_release('TAB') pg.hotkey('TAB') time.sleep(0.5) # pg.alert(2) else: # kb.press_and_release('SHIFT+TAB') pg.hotkey('SHIFT', 'TAB') time.sleep(0.5) browser.press(browser.ENTER) time.sleep(2) # try: # img = "Restore_Bubble.PNG" # pos = pg.locateOnScreen(img, confidence=0.8) #region= # pg.alert(pos) # pg.click(*pos) # except: # pass pg.alert("Ready ! Google Colab is now connected with your Local Runtime.\n\nPlease click 'OK' & you are all set to work on ClointFusion Colabs...") except Exception as ex: print("Error in connect_to_local_runtime="+str(ex)) exc_type, exc_value, exc_tb = sys.exc_info() pg.alert(traceback.format_exception(exc_type, exc_value, exc_tb,limit=None, chain=True)) pg.alert("Error in connect_to_local_runtime="+str(ex)) connect_to_local_runtime()
""" import json import sys from time import sleep from helium import S, click, kill_browser, start_chrome, wait_until from selenium import webdriver from selenium.common.exceptions import TimeoutException from proj_consts import ProjectConsts opts = webdriver.ChromeOptions() opts.set_capability("loggingPrefs", {"performance": "ALL"}) driver = start_chrome(ProjectConsts.BRAZIL_HEALTH_MINISTRY_URL, options=opts) wait_until(S("ion-button").exists) sleep(3) click("Arquivo CSV") global URL URL = None def process_browser_log_entry(entry): response = json.loads(entry["message"])["message"] return response def fetch_download_url(): global URL
if helium.S( "//span[contains(text(),'Sorry, this course is no longer accepting enrollme')]" ).exists(): print( f"{Fore.YELLOW}[!] Cannot enroll in the course at {url} because the course is not " f"accepting enrollments anymore") continue elif helium.S( "//span[contains(text(), ' is no longer available.')]").exists(): print(f"{Fore.YELLOW}[!] The course at {url} does not exist anymore") continue elif helium.S("//h1[@class='error__greeting']").exists(): print(f"{Fore.YELLOW}[!] The {url} does not exist") continue try: helium.wait_until(helium.S("//h1[@data-purpose='lead-title']").exists) course_name = helium.S( "//h1[@data-purpose='lead-title']").web_element.text except TimeoutException: continue enroll_test = is_enroll_possible() if enroll_test is not True: print( f"{Fore.YELLOW}[!] Cannot enroll in '{course_name}' because {enroll_test}" ) continue try: helium.wait_until(helium.Button(enroll_label).exists) helium.click(helium.Button(enroll_label))
def _open_popup(self): click("Open popup") wait_until(self._is_in_popup)
def setUp(self): super(AlertAT, self).setUp() click(self.get_link_to_open_alert()) wait_until(Alert().exists)
def setUpClass(cls): super().setUpClass() go_to(get_data_file_url('test_window/test_window.html')) click("Click here to open a popup.") wait_until(Window('test_window - popup').exists)
import helium import hashlib driver = helium.start_chrome("https://temp-mail.org/en/", headless=True) helium.wait_until( lambda: "@" in helium.TextField("Your Temporary email address").value) email = helium.TextField("Your Temporary email address").value password = hashlib.sha1(email.encode()).hexdigest() print(email, password) helium.kill_browser() driver = helium.start_chrome("https://www.kartable.fr/inscription") helium.click("élève") helium.click("1ère") helium.click("s'inscrire avec un e-mail") helium.write("Cld", into="prénom") helium.write("Lokidod", into="nom") helium.write(email, into="adresse e-mail") helium.write(password, into="mot de passe") helium.click("terminer") helium.wait_until(helium.Text("plus tard").exists) helium.click("plus tard") #helium.kill_browser()
return False # the id you want to check goods_id = "00718624969" # family url family = "https://www.famiport.com.tw/Web_Famiport/page/process.aspx" # init browser options = FirefoxOptions() options.add_argument("--width=800") options.add_argument("--height=800") driver = helium.start_firefox(family, options=options) # wait until web completely loaded helium.wait_until(helium.Text("※請輸入驗證碼。").exists) # find all textfield textfields = helium.find_all(helium.TextField()) # write to the fisrt goods helium.write(goods_id, into=textfields[2]) # scroll down for viewing verification code and take screenshot helium.scroll_down(500) driver.save_screenshot("temp.png") # read from screen shot as gray image img = cv2.imread("temp.png", cv2.IMREAD_GRAYSCALE) # convert to only black and white