Created
May 12, 2022 15:02
-
-
Save andrew-ma/a0fa81dbc9f5e46abf540dd66b6ab339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% | |
from selenium import webdriver | |
from selenium.webdriver.chrome.service import Service | |
from selenium.webdriver.chrome.options import Options | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
# %% | |
from webdriver_manager.chrome import ChromeDriverManager | |
#%% | |
chromedriver_executable_path = ChromeDriverManager().install() | |
print(chromedriver_executable_path) | |
#%% | |
chrome_service = Service(chromedriver_executable_path) | |
print(chrome_service) | |
#%% | |
chrome_options = Options() | |
print(chrome_options) | |
#%% | |
chrome_options.add_experimental_option("useAutomationExtension", False) | |
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) | |
#%% | |
# Add Ublock Origin Adblock Extension | |
ublock_origin_extension_crx = '/home/s/Desktop/chick_mails/yandex_selenium/src/chrome_extensions/ublock_origin.crx' | |
chrome_options.add_extension(extension=ublock_origin_extension_crx) | |
#%% | |
driver = webdriver.Chrome( | |
service=chrome_service, | |
options=chrome_options | |
) | |
print(driver) | |
###################################### | |
#%% | |
# Open the Yandex 360 Page | |
yandex_360_url = 'https://admin.yandex.ru/users?uid=1585643669' | |
driver.get(yandex_360_url) | |
# %% | |
yandex_login_input_id = 'passp-field-login' | |
login_input_el = driver.find_element( | |
by=By.ID, | |
value=yandex_login_input_id | |
) | |
login_input_el.click() | |
#%% | |
YANDEX_USERNAME = 'TODO' | |
#%% | |
login_input_el.send_keys(YANDEX_USERNAME) | |
#%% | |
submit_login_button_id = 'passp\:sign-in' | |
submit_login_button_el = driver.find_element( | |
by=By.ID, | |
value=submit_login_button_id | |
) | |
submit_login_button_el.click() | |
#%% | |
password_input_id = 'passp-field-passwd' | |
password_input_el = driver.find_element( | |
by=By.ID, | |
value=password_input_id | |
) | |
password_input_el.click() | |
#%% | |
YANDEX_PASSWORD = 'TODO' | |
password_input_el.send_keys(YANDEX_PASSWORD) | |
# %% | |
submit_password_button_id = 'passp\:sign-in' | |
submit_password_button_el = driver.find_element( | |
by=By.ID, | |
value=submit_password_button_id | |
) | |
submit_password_button_el.click() | |
# %% | |
# Handle the Mobile 2FA text screen | |
mobile_2fa_submit_button_css_selector = 'button[type="submit"]' | |
mobile_2fa_submit_button_el = driver.find_element( | |
by=By.CSS_SELECTOR, | |
value=mobile_2fa_submit_button_css_selector | |
) | |
mobile_2fa_submit_button_el.click() | |
# %% | |
yandex_mobile_2fa_code = '628-882' | |
#%% | |
mobile_2fa_code_input_id = 'passp-field-phoneCode' | |
mobile_2fa_code_input_el = driver.find_element( | |
by=By.ID, | |
value=mobile_2fa_code_input_id | |
) | |
mobile_2fa_code_input_el.click() | |
#%% | |
mobile_2fa_code_input_el.send_keys(yandex_mobile_2fa_code) | |
#%% | |
mobile_2fa_code_submit_button_css_selector = 'button[type="submit"]' | |
mobile_2fa_code_submit_button_el = driver.find_element( | |
by=By.CSS_SELECTOR, | |
value=mobile_2fa_code_submit_button_css_selector | |
) | |
mobile_2fa_code_submit_button_el.click() | |
#%% | |
############################################################################ | |
### Reach 'Select organization' page | |
############################################################################ | |
first_organization_item_css_selector = 'div.js-organization-selection-item' | |
first_organization_item_el = driver.find_element( | |
by=By.CSS_SELECTOR, | |
value=first_organization_item_css_selector | |
) | |
first_organization_item_el.click() | |
#%% | |
driver.get('https://admin.yandex.ru/users?uid=1585643669') | |
#%% | |
################################################################ | |
YANDEX_LASTNAME = 'wyble' | |
YANDEX_FIRSTNAME = 'nolan' | |
# YANDEX_NEW_USERNAME = f'{YANDEX_FIRSTNAME}_{YANDEX_LASTNAME}' | |
YANDEX_NEW_USERNAME = 'nolan_wyble' | |
YANDEX_PASSWORD = 'RandomPassword70!' | |
################################################################ | |
#%% | |
######################################## | |
### 'Add employee' button | |
######################################## | |
# Find the element that contains the text "Add employee", then get its ancestor that is a button type | |
add_employee_button_xpath = '//*[contains(text(), "Add employee")]/ancestor::button' | |
add_employee_button_el = driver.find_element( | |
by=By.XPATH, | |
value=add_employee_button_xpath | |
) | |
print(add_employee_button_el.text) | |
print(add_employee_button_el.tag_name) | |
#%% | |
add_employee_button_el.click() | |
# %% | |
######################################## | |
### 'Add employee' form popup | |
######################################## | |
last_name_input_css_selector = 'input[name="last_name"]' | |
last_name_input_el = driver.find_element( | |
by=By.CSS_SELECTOR, | |
value=last_name_input_css_selector | |
) | |
last_name_input_el.click() | |
#%% | |
last_name_input_el.send_keys(YANDEX_LASTNAME) | |
#%% | |
first_name_input_css_selector = 'input[name="first_name"]' | |
first_name_input_el = driver.find_element( | |
by=By.CSS_SELECTOR, | |
value=first_name_input_css_selector | |
) | |
#%% | |
first_name_input_el.send_keys(YANDEX_FIRSTNAME) | |
#%% | |
new_username_input_css_selector = 'input[name="nickname"]' | |
new_username_input_el = driver.find_element( | |
by=By.CSS_SELECTOR, | |
value=new_username_input_css_selector | |
) | |
new_username_input_el.click() | |
#%% | |
# new username field is for: NEW_USERNAME@customdomain.com | |
new_username_input_el.send_keys(YANDEX_NEW_USERNAME) | |
#%% | |
password_input_css_selector = 'input[name="password_field_1"]' | |
password_input_el = driver.find_element( | |
by=By.CSS_SELECTOR, | |
value=password_input_css_selector | |
) | |
password_input_el.click() | |
password_input_el.send_keys(YANDEX_PASSWORD) | |
#%% | |
password_confirmation_input_css_selector = 'input[name="password_field_2"]' | |
password_confirmation_input_el = driver.find_element( | |
by=By.CSS_SELECTOR, | |
value=password_confirmation_input_css_selector | |
) | |
password_confirmation_input_el.click() | |
password_confirmation_input_el.send_keys(YANDEX_PASSWORD) | |
#%% | |
language_button_xpath = '//label[contains(text(), "Language")]/following-sibling::button' | |
language_button_el = driver.find_element( | |
by=By.XPATH, | |
value=language_button_xpath | |
) | |
language_button_el.click() | |
# %% | |
language_dropdown_english_xpath = '//span[contains(text(), "English")]/ancestor::div[@data-key="item-1"]' | |
language_dropdown_english_el = driver.find_element( | |
by=By.XPATH, | |
value=language_dropdown_english_xpath | |
) | |
language_dropdown_english_el.click() | |
# %% | |
save_button_xpath = '//*[contains(text(), "Save")]/ancestor::button' | |
save_button_el = driver.find_element( | |
by=By.XPATH, | |
value=save_button_xpath | |
) | |
save_button_el.click() | |
# %% | |
# %% | |
# %% | |
# %% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment