Пример #1
0
def check_ie_driver_settings():
    ie_subprocess = subprocess.Popen(r'"C:\Program Files\Internet Explorer\iexplore.exe" www.google.com')
    settings_button = pythonRPA.bySelector([{"title": "Google - Internet Explorer", "class_name": "IEFrame", "backend": "uia"}, {"depth_start": 4, "depth_end": 4, "title": "Tools", "control_type": "Button"}])
    settings_button.wait_appear(5)
    settings_button.click()
    sleep(0.2)
    pythonRPA.keyboard.press("down", 10)
    pythonRPA.keyboard.press("enter")
    sleep(0.2)
    pythonRPA.keyboard.press("ctrl+tab")

    enabled_checkbox = pythonRPA.byImage("./Utils/enable_protected_mode_ie_2.png")
    if enabled_checkbox.is_exists():
        enabled_checkbox.click()

    sleep(0.2)
    pythonRPA.keyboard.press("enter")
    sleep(0.2)
    pythonRPA.keyboard.press("enter")

    os.system("taskkill /f /im iexplore.exe")
Пример #2
0
def after_choose_button_clicked():
    edit_button = pythonRPA.bySelector([{
        "title":
        "Система управления бизнес процессами - Пользователи - Internet Explorer",
        "class_name": "IEFrame",
        "backend": "uia"
    }, {
        "depth_start": 16,
        "depth_end": 16,
        "title": "Изменить",
        "control_type": "Button"
    }])
    edit_button.click()

    gruppa_ispolnitelei_area = pythonRPA.bySelector([{
        "title":
        "Система управления бизнес процессами - Пользователи - Internet Explorer",
        "class_name": "IEFrame",
        "backend": "uia"
    }, {
        "ctrl_index": 2
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 2
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 1
    }, {
        "ctrl_index": 2
    }, {
        "ctrl_index": 3
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 7
    }, {
        "ctrl_index": 1
    }, {
        "ctrl_index": 1
    }, {
        "ctrl_index": 0,
        "control_type": "List"
    }])
    gruppa_ispolnitelei_area.wait_appear(5)
    if not gruppa_ispolnitelei_area.is_exists():
        gruppa_ispolnitelei_area = pythonRPA.bySelector([{
            "title":
            "Система управления бизнес процессами - Пользователи - Internet Explorer",
            "class_name": "IEFrame",
            "backend": "uia"
        }, {
            "ctrl_index": 3
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 2
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 1
        }, {
            "ctrl_index": 2
        }, {
            "ctrl_index": 3
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 7
        }, {
            "ctrl_index": 1
        }, {
            "ctrl_index": 1
        }, {
            "ctrl_index": 0,
            "control_type": "List"
        }])

    if len(gruppa_ispolnitelei_area.texts()) > 0:
        # print(len(gruppa_ispolnitelei_area.texts()))
        for i in range(len(gruppa_ispolnitelei_area.texts())):
            delete_button = pythonRPA.bySelector([{
                "title":
                "Система управления бизнес процессами - Пользователи - Internet Explorer",
                "class_name": "IEFrame",
                "backend": "uia"
            }, {
                "ctrl_index": 2
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 2
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 1
            }, {
                "ctrl_index": 2
            }, {
                "ctrl_index": 3
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 7
            }, {
                "ctrl_index": 1
            }, {
                "ctrl_index": 2
            }, {
                "title": "Удалить",
                "control_type": "Button"
            }])
            delete_button.wait_appear(5)
            if not delete_button.is_exists():
                delete_button = pythonRPA.bySelector([{
                    "title":
                    "Система управления бизнес процессами - Пользователи - Internet Explorer",
                    "class_name": "IEFrame",
                    "backend": "uia"
                }, {
                    "ctrl_index": 3
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 2
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 1
                }, {
                    "ctrl_index": 2
                }, {
                    "ctrl_index": 3
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 7
                }, {
                    "ctrl_index": 1
                }, {
                    "ctrl_index": 2
                }, {
                    "title": "Удалить",
                    "control_type": "Button"
                }])

            gruppa_ispolnitelei_area.wait_appear(60)
            gruppa_ispolnitelei_area.click()
            pythonRPA.keyboard.press("up")
            delete_button.click()
            pythonRPA.mouse.click(400, 780)

    roli_area = pythonRPA.bySelector([{
        "title":
        "Система управления бизнес процессами - Пользователи - Internet Explorer",
        "class_name": "IEFrame",
        "backend": "uia"
    }, {
        "ctrl_index": 2
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 2
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 1
    }, {
        "ctrl_index": 2
    }, {
        "ctrl_index": 3
    }, {
        "ctrl_index": 0
    }, {
        "ctrl_index": 7
    }, {
        "ctrl_index": 2
    }, {
        "ctrl_index": 1
    }, {
        "ctrl_index": 0,
        "control_type": "List"
    }])
    roli_area.wait_appear(10)
    if not roli_area.is_exists():
        roli_area = pythonRPA.bySelector([{
            "title":
            "Система управления бизнес процессами - Пользователи - Internet Explorer",
            "class_name": "IEFrame",
            "backend": "uia"
        }, {
            "ctrl_index": 3
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 2
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 1
        }, {
            "ctrl_index": 2
        }, {
            "ctrl_index": 3
        }, {
            "ctrl_index": 0
        }, {
            "ctrl_index": 7
        }, {
            "ctrl_index": 2
        }, {
            "ctrl_index": 1
        }, {
            "ctrl_index": 0,
            "control_type": "List"
        }])
        roli_area.wait_appear(10)

    if len(roli_area.texts()) > 0:
        # print(len(roli_area.texts()))
        for i in range(len(roli_area.texts())):
            delete_button2 = pythonRPA.bySelector([{
                "title":
                "Система управления бизнес процессами - Пользователи - Internet Explorer",
                "class_name": "IEFrame",
                "backend": "uia"
            }, {
                "ctrl_index": 2
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 2
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 1
            }, {
                "ctrl_index": 2
            }, {
                "ctrl_index": 3
            }, {
                "ctrl_index": 0
            }, {
                "ctrl_index": 7
            }, {
                "ctrl_index": 2
            }, {
                "ctrl_index": 2
            }, {
                "title": "Удалить",
                "control_type": "Button"
            }])
            delete_button2.wait_appear(5)
            if not delete_button2.is_exists():
                delete_button2 = pythonRPA.bySelector([{
                    "title":
                    "Система управления бизнес процессами - Пользователи - Internet Explorer",
                    "class_name": "IEFrame",
                    "backend": "uia"
                }, {
                    "ctrl_index": 3
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 2
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 1
                }, {
                    "ctrl_index": 2
                }, {
                    "ctrl_index": 3
                }, {
                    "ctrl_index": 0
                }, {
                    "ctrl_index": 7
                }, {
                    "ctrl_index": 2
                }, {
                    "ctrl_index": 2
                }, {
                    "title": "Удалить",
                    "control_type": "Button"
                }])
                delete_button2.wait_appear(5)

            roli_area.wait_appear(30)
            roli_area.click()
            pythonRPA.keyboard.press("up")
            delete_button2.click()
            pythonRPA.mouse.click(400, 780)

    # add_button = pythonRPA.bySelector(
    #     [{"title": "Система управления бизнес процессами - Пользователи - Internet Explorer",
    #       "class_name": "IEFrame", "backend": "uia"}, {"ctrl_index": 3}, {"ctrl_index": 0},
    #      {"ctrl_index": 0}, {"ctrl_index": 0}, {"ctrl_index": 0}, {"ctrl_index": 0},
    #      {"ctrl_index": 2}, {"ctrl_index": 0}, {"ctrl_index": 1}, {"ctrl_index": 2},
    #      {"ctrl_index": 3}, {"ctrl_index": 0}, {"ctrl_index": 7}, {"ctrl_index": 2},
    #      {"ctrl_index": 2}, {"title": "Добавить", "control_type": "Button"}])
    # add_button.wait_appear(15)
    # add_button.click()
    pythonRPA.mouse.click(220, 680)

    list_items_number = pythonRPA.bySelector([{
        "title": "Список ролей - Internet Explorer",
        "class_name": "IEFrame",
        "backend": "uia"
    }, {
        "depth_start": 15,
        "depth_end": 15,
        "title": "Open",
        "control_type": "Button"
    }])
    list_items_number.wait_appear(30)
    list_items_number.click()
    sleep(1)
    pythonRPA.keyboard.press("down", 5)
    pythonRPA.keyboard.press("enter")
    pythonRPA.mouse.scroll(6)

    roles_list = pythonRPA.bySelector([{
        "title": "Список ролей - Internet Explorer",
        "class_name": "IEFrame",
        "backend": "uia"
    }])
    roles_list.click()
    pythonRPA.keyboard.press("down", 40)

    # member_menu_item = pythonRPA.bySelector()
    member_menu_item = pythonRPA.byImage(r".\Utils\word_member.png")
    member_menu_item.wait_appear(15)
    # print(member_menu_item.attrs())
    attrs = member_menu_item.attrs()
    left = attrs.left
    top = attrs.top
    # print(left)
    # print(top)
    pythonRPA.mouse.click(left - 30, top + 5)
    # member_menu_item.near( near_image_path=r"C:\Users\mazhit.e\Desktop\ttt\PythonRPA-master\Robot\Blocking_Robot\Utils\href_select.png",position="right", distance_in_px=20)

    # select_member_menu_item.click()

    final_select_button = pythonRPA.bySelector([{
        "title": "Список ролей - Internet Explorer",
        "class_name": "IEFrame",
        "backend": "uia"
    }, {
        "depth_start": 14,
        "depth_end": 14,
        "title": "Выбрать",
        "control_type": "Button"
    }])
    final_select_button.click()
    sleep(2)

    pythonRPA.mouse.click(550, 370)
    pythonRPA.keyboard.press("ctrl+a")
    pythonRPA.keyboard.press("delete")

    sleep(2)

    nomad_checkbox_clicked = pythonRPA.byImage(r".\Utils\nomad_checkbox.png")
    if nomad_checkbox_clicked.is_exists():
        nomad_checkbox = pythonRPA.bySelector([{
            "title":
            "Система управления бизнес процессами - Пользователи - Internet Explorer",
            "class_name": "IEFrame",
            "backend": "uia"
        }, {
            "depth_start": 16,
            "depth_end": 16,
            "title": "",
            "control_type": "CheckBox"
        }])
        nomad_checkbox.click()

    sleep(2)

    ok_button = pythonRPA.bySelector([{
        "title":
        "Система управления бизнес процессами - Пользователи - Internet Explorer",
        "class_name": "IEFrame",
        "backend": "uia"
    }, {
        "depth_start": 16,
        "depth_end": 16,
        "title": "OK",
        "control_type": "Button"
    }])
    ok_button.click()
Пример #3
0
def block_bpm(name):
    log_bpm_status = "Success"
    log_comments = ""

    #href = "Users.aspx"
    # WebDriverWait(driver, 20).until(
    #     EC.presence_of_all_elements_located((By.XPATH, "//a[@href = 'Site/Administration/Users.aspx']")))
    # users_menuOption = driver.find_element(By.XPATH, "//a[@href = 'Site/Administration/Users.aspx']")
    # users_menuOption.click()
    WebDriverWait(driver, 20).until(
        EC.presence_of_all_elements_located(
            (By.XPATH, "//a[text() = 'Пользователи']")))
    users_menuOption = driver.find_element(By.XPATH,
                                           "//a[text() = 'Пользователи']")
    users_menuOption.click()

    WebDriverWait(driver, 10).until(
        EC.presence_of_all_elements_located(
            (By.CSS_SELECTOR, "input#TB_Search_FullName")))
    name_field = driver.find_element(By.CSS_SELECTOR,
                                     "input#TB_Search_FullName")
    name_field.send_keys(name)

    WebDriverWait(driver, 10).until(
        EC.presence_of_all_elements_located(
            (By.CSS_SELECTOR, "input#Button_Search")))
    search_button = driver.find_element(By.CSS_SELECTOR, "input#Button_Search")
    search_button.click()

    WebDriverWait(driver, 10).until(
        EC.presence_of_all_elements_located(
            (By.CSS_SELECTOR, "table#GV_IpotekaUsers")))
    results_table = driver.find_element(By.CSS_SELECTOR,
                                        "table#GV_IpotekaUsers")
    results_table_rows = results_table.find_elements(By.XPATH, ".//tr")
    print(len(results_table_rows))

    iterable = iter(results_table_rows)
    next(iterable)
    row_counter = 0
    for row in iterable:
        #print(row.get_attribute('innerHTML'))
        href_value = "javascript:__doPostBack('GV_IpotekaUsers','Select$" + str(
            row_counter) + "')"

        # WebDriverWait(driver, 10).until(
        #     EC.presence_of_all_elements_located((By.XPATH, ".//a")))
        # choose_button = row.find_element(By.XPATH, ".//a")    and text()='Выбрать'
        WebDriverWait(driver, 20).until(
            EC.presence_of_all_elements_located(
                (By.XPATH,
                 "//a[@href[contains(., 'Select$%s')]]" % row_counter)))
        choose_button = driver.find_element(
            By.XPATH, "//a[@href[contains(., 'Select$%s')]]" % row_counter)
        sleep(1)
        choose_button.click()
        sleep(1)
        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "input#IB_Update")))
        edit_button = driver.find_element(By.CSS_SELECTOR, "input#IB_Update")
        edit_button.click()

        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "input#TB_Nomad")))
        nomad_field = driver.find_element(By.CSS_SELECTOR, "input#TB_Nomad")
        nomad_field_value = nomad_field.get_attribute('value')
        print(len(nomad_field_value))
        if len(nomad_field_value) > 0:
            nomad_field.click()
            nomad_field.send_keys(Keys.CONTROL, "a")
            nomad_field.send_keys(Keys.DELETE)

        # x, y = pyautogui.locateCenterOnScreen(r"..\Utils\nomad_checkbox_chrome.png")
        # pythonRPA.mouse.click(x + 100, y)
        nomad_checkbox_clicked = pythonRPA.byImage(
            r"..\Utils\nomad_checkbox_chrome.png")
        if nomad_checkbox_clicked.is_exists():
            print("True")
            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "input#NomadEnabled")))
            nomad_checkbox = driver.find_element(By.CSS_SELECTOR,
                                                 "input#NomadEnabled")
            nomad_checkbox.click()
        else:
            print("False")

        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "input#Button_DeleteExecutor")))
        delete_button_gruppy = driver.find_element(
            By.CSS_SELECTOR, "input#Button_DeleteExecutor")
        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "input#Button_DeleteRole")))
        delete_button_roli = driver.find_element(By.CSS_SELECTOR,
                                                 "input#Button_DeleteRole")

        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "select#LB_UserDepExecutors")))
        gruppy_ispolnitelei_area = driver.find_element(
            By.CSS_SELECTOR, "select#LB_UserDepExecutors")
        gruppy_ispolnitelei_items = gruppy_ispolnitelei_area.find_elements(
            By.XPATH, ".//option")
        print(len(gruppy_ispolnitelei_items))
        for item in range(len(gruppy_ispolnitelei_items)):
            driver.find_element(By.CSS_SELECTOR,
                                "select#LB_UserDepExecutors").click()
            driver.find_element(By.CSS_SELECTOR,
                                "select#LB_UserDepExecutors").send_keys(
                                    Keys.UP)
            sleep(0.5)
            driver.find_element(By.CSS_SELECTOR,
                                "input#Button_DeleteExecutor").click()
            sleep(1)

        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "select#LB_UserRoles")))
        roli_area = driver.find_element(By.CSS_SELECTOR, "select#LB_UserRoles")
        roli_items = roli_area.find_elements(By.XPATH, ".//option")
        print(len(roli_items))
        for item in range(len(roli_items)):
            driver.find_element(By.CSS_SELECTOR, "select#LB_UserRoles").click()
            driver.find_element(By.CSS_SELECTOR,
                                "select#LB_UserRoles").send_keys(Keys.UP)
            sleep(0.5)
            driver.find_element(By.CSS_SELECTOR,
                                "input#Button_DeleteRole").click()
            sleep(1)

        sleep(2)
        driver.find_element(By.CSS_SELECTOR, "input#Button_AddRole").click()

        sleep(3)

        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "input#Button_OK")))
        ok_button = driver.find_element(By.CSS_SELECTOR, "input#Button_OK")
        ok_button.click()

        row_counter += 1

    print("iteration ended")
    # for i in range(len(results_table_rows)-1):
    #     print("Hola"+str(i))
    #     choose_button
    # else:
    #     log_bpm_status = "Failed"
    #     log_comments = "Not found in system"
    #
    return log_bpm_status, log_comments
Пример #4
0
def block_bpm(name):
    log_bpm_status = "Заблокирован"
    log_comments = ""

    #href = "Users.aspx"
    # WebDriverWait(driver, 20).until(
    #     EC.presence_of_all_elements_located((By.XPATH, "//a[@href = 'Site/Administration/Users.aspx']")))
    # users_menuOption = driver.find_element(By.XPATH, "//a[@href = 'Site/Administration/Users.aspx']")
    # users_menuOption.click()

    WebDriverWait(driver, 20).until(
        EC.presence_of_all_elements_located(
            (By.XPATH, "//a[text() = 'Пользователи']")))
    users_menuOption = driver.find_element(By.XPATH,
                                           "//a[text() = 'Пользователи']")
    users_menuOption.click()

    sleep(0.5)

    WebDriverWait(driver, 10).until(
        EC.presence_of_all_elements_located(
            (By.CSS_SELECTOR, "input#TB_Search_FullName")))
    name_field = driver.find_element(By.CSS_SELECTOR,
                                     "input#TB_Search_FullName")
    name_field.send_keys(name)

    WebDriverWait(driver, 10).until(
        EC.presence_of_all_elements_located(
            (By.CSS_SELECTOR, "input#Button_Search")))
    search_button = driver.find_element(By.CSS_SELECTOR, "input#Button_Search")
    search_button.click()

    if __selenium_wait_element(By.CSS_SELECTOR, "table#GV_IpotekaUsers"):
        WebDriverWait(driver, 10).until(
            EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "table#GV_IpotekaUsers")))
        results_table = driver.find_element(By.CSS_SELECTOR,
                                            "table#GV_IpotekaUsers")
        results_table_rows = results_table.find_elements(By.XPATH, ".//tr")
        print(len(results_table_rows))

        iterable = iter(results_table_rows)
        next(iterable)
        row_counter = 0
        for row in iterable:
            #print(row.get_attribute('innerHTML'))
            href_value = "javascript:__doPostBack('GV_IpotekaUsers','Select$" + str(
                row_counter) + "')"

            # WebDriverWait(driver, 10).until(
            #     EC.presence_of_all_elements_located((By.XPATH, ".//a")))
            # choose_button = row.find_element(By.XPATH, ".//a")    and text()='Выбрать'
            WebDriverWait(driver, 20).until(
                EC.presence_of_all_elements_located((
                    By.XPATH,
                    "//a[text() = 'Выбрать' and @href[contains(., 'Select$%s')]]"
                    % row_counter)))
            choose_button = driver.find_element(
                By.XPATH,
                "//a[text() = 'Выбрать' and @href[contains(., 'Select$%s')]]" %
                row_counter)
            sleep(0.3)
            choose_button.click()
            sleep(0.2)
            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "input#IB_Update")))
            edit_button = driver.find_element(By.CSS_SELECTOR,
                                              "input#IB_Update")
            edit_button.click()

            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "input#TB_Nomad")))
            nomad_field = driver.find_element(By.CSS_SELECTOR,
                                              "input#TB_Nomad")
            nomad_field_value = nomad_field.get_attribute('value')
            print(len(nomad_field_value))
            if len(nomad_field_value) > 0:
                nomad_field.click()
                nomad_field.send_keys(Keys.CONTROL, "a")
                nomad_field.send_keys(Keys.DELETE)

            # x, y = pyautogui.locateCenterOnScreen(r"..\Utils\nomad_checkbox_chrome.png")
            # pythonRPA.mouse.click(x + 100, y)
            nomad_checkbox_clicked = pythonRPA.byImage(
                r".\Utils\nomad_checkbox.png")
            if nomad_checkbox_clicked.is_exists():
                print("True")
                WebDriverWait(driver, 10).until(
                    EC.presence_of_all_elements_located(
                        (By.CSS_SELECTOR, "input#NomadEnabled")))
                nomad_checkbox = driver.find_element(By.CSS_SELECTOR,
                                                     "input#NomadEnabled")
                nomad_checkbox.click()
            else:
                print("False")

            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "input#Button_DeleteExecutor")))
            delete_button_gruppy = driver.find_element(
                By.CSS_SELECTOR, "input#Button_DeleteExecutor")
            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "input#Button_DeleteRole")))
            delete_button_roli = driver.find_element(
                By.CSS_SELECTOR, "input#Button_DeleteRole")

            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "select#LB_UserDepExecutors")))
            gruppy_ispolnitelei_area = driver.find_element(
                By.CSS_SELECTOR, "select#LB_UserDepExecutors")
            gruppy_ispolnitelei_items = gruppy_ispolnitelei_area.find_elements(
                By.XPATH, ".//option")
            print(len(gruppy_ispolnitelei_items))
            for item in range(len(gruppy_ispolnitelei_items)):
                driver.find_element(By.CSS_SELECTOR,
                                    "select#LB_UserDepExecutors").click()
                driver.find_element(By.CSS_SELECTOR,
                                    "select#LB_UserDepExecutors").send_keys(
                                        Keys.UP)
                sleep(0.5)
                driver.find_element(By.CSS_SELECTOR,
                                    "input#Button_DeleteExecutor").click()
                sleep(0.5)

            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "select#LB_UserRoles")))
            roli_area = driver.find_element(By.CSS_SELECTOR,
                                            "select#LB_UserRoles")
            roli_items = roli_area.find_elements(By.XPATH, ".//option")
            print(len(roli_items))
            for item in range(len(roli_items)):
                driver.find_element(By.CSS_SELECTOR,
                                    "select#LB_UserRoles").click()
                driver.find_element(By.CSS_SELECTOR,
                                    "select#LB_UserRoles").send_keys(Keys.UP)
                sleep(0.3)
                driver.find_element(By.CSS_SELECTOR,
                                    "input#Button_DeleteRole").click()
                sleep(0.3)

            sleep(0.5)
            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "input#Button_AddRole")))
            driver.find_element(By.CSS_SELECTOR,
                                "input#Button_AddRole").click()
            main_page = driver.current_window_handle
            #print(main_page)
            #print("----------------------------------------")
            sleep(3)
            for handle in driver.window_handles:
                if handle != main_page:
                    #print(handle)
                    add_role_window = handle
                    break
            driver.switch_to.window(add_role_window)

            # driver.switch_to.window(driver.window_handles[-1])
            # sleep(1)
            # print(driver.current_window_handle)

            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "select#DDL_PageSize")))
            select_button = driver.find_element(By.CSS_SELECTOR,
                                                "select#DDL_PageSize")
            select_button.click()
            sleep(0.5)
            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.XPATH, ".//option[text()='Все']")))
            all_option = select_button.find_element(By.XPATH,
                                                    ".//option[text()='Все']")
            all_option.click()
            sleep(0.5)
            roles_table = driver.find_element(By.CSS_SELECTOR,
                                              "table#GV_Roles")
            uchastnik_role_item = roles_table.find_element(
                By.XPATH, ".//tr[td[text()='Участник']]")
            select_role_button = uchastnik_role_item.find_element(
                By.XPATH, ".//a")
            select_role_button.click()
            sleep(0.5)
            driver.find_element(By.CSS_SELECTOR, "input#IB_Select").click()
            sleep(0.5)
            #driver.close()
            sleep(0.5)
            driver.switch_to.window(main_page)

            WebDriverWait(driver, 10).until(
                EC.presence_of_all_elements_located(
                    (By.CSS_SELECTOR, "input#Button_OK")))
            ok_button = driver.find_element(By.CSS_SELECTOR, "input#Button_OK")
            ok_button.click()

            row_counter += 1
    else:
        log_bpm_status = "Не заблокирован"
        log_comments = "Сотрудник не найден в системе"
    print("iteration ended")
    # for i in range(len(results_table_rows)-1):
    #     print("Hola"+str(i))
    #     choose_button
    # else:
    #     log_bpm_status = "Failed"
    #     log_comments = "Not found in system"
    #
    return log_bpm_status, log_comments
Пример #5
0
def block(names,log_table):
    # start Active  Directory
    pythonRPA.keyboard.press('win + R')
    Run = pythonRPA.bySelector([{"title": "Run", "backend": "win32"}])
    Run.wait_appear(2)
    pythonRPA.keyboard.write('dsa.msc')
    pythonRPA.keyboard.press('Enter')

    # clicking the SEARCH button to open the search window
    AD_main = pythonRPA.bySelector(
        [{"title": "Active Directory Users and Computers", "class_name": "MMCMainFrame", "backend": "win32"}])
    AD_main.wait_appear(5)
    AD_main.set_focus()
    AD_main.maximize()
    print("Active Directory opened well!")

    #Action click
    pyautogui.click(62, 36)
    #change_domain click
    while 1:
        try:
            x, y = pyautogui.locateCenterOnScreen(r'.\Utils\change_domain.png')
            pyautogui.click(x, y)
            print('change domain clickd !')
            pythonRPA.sleep(2)
            break
        except Exception as e:
            print(e)
    pythonRPA.keyboard.press('Enter')
    pythonRPA.sleep(2)
    # # click hcsbk
    # pythonRPA.keyboard.press('down')
    # pythonRPA.sleep(2)
    # pythonRPA.keyboard.press('Enter')
    while 1:
        try:
            x, y = pyautogui.locateCenterOnScreen(r'.\Utils\hcsbk.png')
            pyautogui.doubleClick(x, y)
            pythonRPA.sleep(2)
            print('clicked hcsbk well !')
            break
        except Exception as e:
            print(e)

    while 1:
        try:
            x, y = pyautogui.locateCenterOnScreen(r'.\Utils\SEARCH.png')
            pyautogui.doubleClick(x, y)
            break
        except Exception as e:
            print(e)
    find_users = pythonRPA.bySelector(
        [{"title": "Find Users, Contacts, and Groups", "class_name": "#32770", "backend": "win32"}])
    find_users.wait_appear(2)
    find_users.set_focus()
    find_users.maximize()

    for name in names:
        try:
            # log_ad_status = "Success"
            # log_ad_comment = ""
            success = 0
            # searching the accounts by full names
            if name != None and name == 'test test test':
                search_by_name = pythonRPA.bySelector(
                    [{"title": "Find Users, Contacts, and Groups", "class_name": "#32770", "backend": "win32"},
                     {"ctrl_index": 152},{"ctrl_index": 7}])
                clear_button = pythonRPA.bySelector(
                    [{"title": "Find Users, Contacts, and Groups", "class_name": "#32770", "backend": "win32"},
                     {"ctrl_index": 14}])
                clear_button.click()
                pythonRPA.keyboard.press('Enter')
                search_by_name.wait_appear(1)
                search_by_name.click()
                pythonRPA.keyboard.write(name)
                pythonRPA.sleep(1)
                search_ok = pythonRPA.bySelector(
                    [{"title": "Find Users, Contacts, and Groups", "class_name": "#32770", "backend": "win32"},
                     {"ctrl_index": 12}])
                search_ok.click()
                pythonRPA.sleep(3)
                # clicking the result
                found = False
                for i in range(5):
                    try:
                        x,y = pyautogui.locateCenterOnScreen(r'.\Utils\found.PNG')
                        found = True
                        break
                    except Exception as e:
                        print(e)

                if found:
                    x = 178
                    y = 340
                    pyautogui.rightClick(x, y)

                    # make an account disable
                    for i in range(5):
                        try:
                            a,b = pyautogui.locateCenterOnScreen(r'.\Utils\enable_condition.png')
                            for i in range(4):
                                pythonRPA.keyboard.press('down')
                                print(a,b)
                            pythonRPA.keyboard.press('Enter')
                            pythonRPA.sleep(1)
                            pythonRPA.keyboard.press('Enter')
                            is_enable =  True
                            break
                        except: continue

                    #
                    success += 1
                    print(success)

                    # Удаляем члены групп
                    # открытие свойств
                    pyautogui.rightClick(x, y)
                    pythonRPA.keyboard.press('up arrow')
                    pythonRPA.sleep(1)
                    pythonRPA.keyboard.press('Enter')
                    pythonRPA.sleep(3)

                    name_variants = get_profile_name(name)
                    for i in range(len(name_variants)):
                        try:
                            user_profile = pythonRPA.bySelector(
                                [{"title":name_variants[i] + " Properties", "class_name": "#32770", "backend": "win32"}])
                            user_profile.set_focus()
                            name = name_variants[i]
                            break
                        except Exception as e:
                            print(e)

                    while 1:
                        try:
                            x, y = pyautogui.locateCenterOnScreen(r'.\Utils\member_of.png')
                            pyautogui.doubleClick(x, y)
                            break
                        except Exception as e:
                            print(e)
                    domain_sub_group = pythonRPA.byImage(r'.\Utils\domain_users.png')

                    n = 0

                    try:
                        sub_group = pythonRPA.bySelector(
                            [{"title": name + " Properties", "class_name": "#32770", "backend": "win32"},
                             {"ctrl_index": 17}, {"ctrl_index": 2}])
                        sub_group.wait_appear(1)
                        sub_group.click()
                        pythonRPA.keyboard.press('up')
                        press_key("shift", 5)
                        pythonRPA.keyboard.press("Shift")
                        remove_button = pythonRPA.bySelector(
                            [{"title": name + " Properties", "class_name": "#32770", "backend": "win32"},
                             {"ctrl_index": 0},
                             {"ctrl_index": 4}])
                        remove_button.click()
                        pythonRPA.keyboard.press('left')
                        pythonRPA.sleep(1)
                        pythonRPA.keyboard.press('Enter')
                        warning = pythonRPA.bySelector(
                            [{"title": "Active Directory Domain Services", "class_name": "#32770", "backend": "win32"}])
                        if (warning.is_exists()):
                            pythonRPA.keyboard.press('Enter')
                        ok = pythonRPA.bySelector([{"title":name+" Properties","class_name":"#32770","backend":"win32"},{"ctrl_index":12}])
                        ok.click()
                        pythonRPA.keyboard.press('Enter')
                    except Exception as e:
                        pythonRPA.keyboard.press('Enter')
                        break
                    success += 1
                    print(success)

                    # move this account to th blocked accounts
                    find_users.set_focus()
                    find_users.maximize()
                    clear_button = pythonRPA.bySelector(
                        [{"title": "Find Users, Contacts, and Groups", "class_name": "#32770", "backend": "win32"},
                         {"ctrl_index": 14}])
                    clear_button.click()
                    pythonRPA.keyboard.press('Enter')
                    search_by_name.wait_appear(1)
                    search_by_name.click()
                    pythonRPA.keyboard.write(name)
                    pythonRPA.sleep(1)
                    search_ok = pythonRPA.bySelector(
                        [{"title": "Find Users, Contacts, and Groups", "class_name": "#32770", "backend": "win32"},
                         {"ctrl_index": 12}])
                    search_ok.click()
                    pythonRPA.sleep(3)

                    # clicking the result
                    x = 178
                    y = 340
                    pyautogui.rightClick(x, y)
                    search_by_name.wait_appear(1)
                    search_by_name.click()
                    pyautogui.rightClick(x, y)
                    for i in range(6):
                        pythonRPA.keyboard.press('down arrow')
                    pythonRPA.keyboard.press('Enter')
                    pythonRPA.sleep(1)
                    move_to_block = pythonRPA.bySelector([{"title": "Move ", "class_name": "#32770", "backend": "win32"}])
                    move_to_block.wait_appear(1)
                    move_to_block.set_focus()
                    for i in range(10):
                        pythonRPA.keyboard.press('down arrow')
                    pythonRPA.keyboard.press('Enter')
                    print(name, 'Account added to BLOCK sucsessfully !')
                    pythonRPA.sleep(1)
                    success += 1
                    print(success)
                    if success == 3:
                        log_table.append([name, "Active Directory", "Заблокирован", "", datetime.now().strftime("%H:%M:%S")])
                    else:
                        log_table.append([name, "Active Directory", "Не заблокирован", "Сотрудник не найден в системе", datetime.now().strftime("%H:%M:%S")])
        except Exception as e:
            log_table.append([name, "Active Directory", "Не заблокирован", "Техническая ошибка", datetime.now().strftime("%H:%M:%S")])
    try:
        f = wmi.WMI()
        for p in f.Win32_Process():
         if p.name == 'mmc.exe':
             p.Terminate()
    except Exception as e:
        print(e)