예제 #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-


# Import the robot class from the pyrobot module
from pyrobot import Robot
import os

import ctypes
import multiprocessing
from ctypes import *
from ctypes.wintypes import *


# create an instance of the class
robot = Robot()

# Launch a program
robot.start_program('path')

# print(windll.kernel32)

robot.sleep(1)


robot.key_press('left_windows__(natural_board)')
# robot.press_and_release('r')
robot.key_release('left_windows__(natural_board)')
# robot.sleep(2)
# robot.type_string('string')
예제 #2
0
파일: auto.py 프로젝트: kafaichan/cheers
def run():
	driver = webdriver.Chrome(executable_path= os.path.join(os.getcwd(), "chromedriver_win32", "chromedriver.exe"))
	# driver.maximize_window()
	driver.get("https://eservice.macaotourism.gov.mo/tourist_tax_questionnaire/?lang=0")

	q0s = driver.find_elements_by_class_name("yes")
	q0s[0].click()
	time.sleep(1)

	q0s = driver.find_elements_by_class_name("yes")
	q0s[1].click()
	time.sleep(1)
	
	q1s = driver.find_element_by_xpath("//input[@name='a1']")
	q1s.click()
	time.sleep(1)

	for x in range(1,7):
		xpath = "//input[@name='a1_{}']".format(x)
		q1s_subq = driver.find_element_by_xpath(xpath)
		q1s_subq.click()
	
	q2 = driver.find_element_by_xpath("//input[@name='a2']")
	q2.click()
	time.sleep(1)

	q3 = driver.find_element_by_xpath("//input[@name='a3']")
	choices = [ str(x) for x in range(100, 2000, 100)]
	q3.send_keys(random.choice(choices))
	
	for x in range(1, 7):
		xpath = "//input[@name='a4_{}']".format(x)
		q4_subq = driver.find_element_by_xpath(xpath)
		q4_subq.click()

	q5 = driver.find_elements_by_xpath("//input[@name='a5']")[4]
	q5.click()
	time.sleep(2)

	for x in range(1, 12):
		idx = random.choice([0,1,2,5])
		xpath = "//input[@name='a6_{}']".format(x)
		q6_subq = driver.find_elements_by_xpath(xpath)[idx]
		q6_subq.click()
	time.sleep(1)

	gender = random.randint(0,1)
	q7 = driver.find_elements_by_xpath("//input[@name='gender']")[gender]
	print(q7)
	q7.click()

	age = random.randint(0, 5)
	q8 = driver.find_elements_by_xpath("//input[@name='age']")[age]
	q8.click()

	occup = random.randint(0, 12)
	q9 = driver.find_elements_by_xpath("//input[@name='occupation']")[occup]
	q9.click()

	time.sleep(2)

	confirm_chkbox = driver.find_elements_by_xpath("//input[@type='checkbox']")[-1]
	confirm_chkbox.click()

	img = driver.find_element_by_id("captcha-image")
	# src = img.get_attribute('src')
	# download(src, "tmp.png")
	action_chains = ActionChains(driver)
	action_chains.context_click(img).perform()

	robot = Robot()
	robot.key_press("v")
	robot.key_release("v")
	time.sleep(2)
	robot.key_press(Keys.enter)
	robot.key_release(Keys.enter)
	time.sleep(8)

	# SET download_dir as the default download location of the pop up window
	img_path = os.path.join(Config.download_dir, "captcha_code.php")
	result = test(img_path)
	print("Captcha Code: ", result)

	if os.path.exists(img_path):
		os.remove(img_path)

	captcha_box = driver.find_element_by_xpath("//input[@name='captcha_code']")
	captcha_box.send_keys(result)
	time.sleep(2)

	submit_btn = driver.find_element_by_xpath("//input[@type='submit']")
	submit_btn.click()
	time.sleep(1)

	driver.quit()
예제 #3
0
def dgcUpload(file):

    print('Inside function')
    print(file)
    #Set browser (Firefox) to be opened
    browser = webdriver.Firefox()

    #Open DGC instance on local machine
    dgcWebLink = 'http://localhost:4400/'
    browser.get(dgcWebLink)

    #User credentials
    user_acc = "Admin"
    user_pas = "******"

    #Pass in credentials
    user = browser.find_element_by_css_selector(
        'div.row:nth-child(2) > div:nth-child(1) > span:nth-child(1)')
    user.send_keys(user_acc)

    pass_key = browser.find_element_by_css_selector(
        'div.row:nth-child(3) > div:nth-child(1) > div:nth-child(2) > input:nth-child(1)'
    )
    pass_key.send_keys(user_pas)

    #Click 'Signin' button to login into DGC
    login = browser.find_element_by_css_selector('.uf-normal-button').click()

    #Wait for 20 seconds for the page to load
    timeout = 20
    try:
        WebDriverWait(browser, timeout).until(
            EC.visibility_of_element_located(
                (By.CSS_SELECTOR, 'a.item:nth-child(6)')))
    except TimeoutException:
        print("Browser didn't load properly")
        browser.quit()

    #Click 'Settings' on DGC
    settings = browser.find_element_by_css_selector(
        'a.item:nth-child(6)').click()

    # Wait for 20 seconds for the page to load
    timeout = 20
    try:
        WebDriverWait(browser, timeout).until(
            EC.visibility_of_element_located(
                (By.CSS_SELECTOR, 'li.maintab:nth-child(6)')))
    except TimeoutException:
        print("Browser didn't load properly")
        browser.quit()

    #Click 'Workflows' on the left hand side
    workflows = browser.find_element_by_css_selector(
        'li.maintab:nth-child(6)').click()

    # Wait for 20 seconds for the page to load
    timeout = 10
    try:
        WebDriverWait(browser, timeout).until(
            EC.visibility_of_element_located(
                (By.CSS_SELECTOR, '.fileupload-button')))
    except TimeoutException:
        print("Browser didn't load properly")
        browser.quit()

    #Click 'Deploy' to upload the workflow
    deploy = browser.find_element_by_css_selector('.fileupload-button').click()

    pyperclip.copy(file)

    # Wait for 10 seconds for the page to load
    for i in range(1, 25):
        print('')

    robot = Robot()
    robot.paste()

    # Wait for 10 seconds for the page to load
    for i in range(1, 25):
        print('')

    robot.key_press('enter')
    print('pressed enter')

    # browser.find_element_by_xpath("//button[contains(text(), 'Open')]").click()

    robot.key_release('enter')
    print('released enter')