2023-12-02 14:13:38 -05:00
|
|
|
#!/usr/bin/env python3
|
2024-08-26 14:55:36 -04:00
|
|
|
# © 2021-2024 TechnoLibre (http://www.technolibre.ca)
|
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
|
|
|
|
|
2024-01-04 23:50:42 -05:00
|
|
|
import argparse
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
2024-01-11 00:51:34 -05:00
|
|
|
import time
|
2024-01-04 23:50:42 -05:00
|
|
|
|
2024-07-07 02:58:38 -04:00
|
|
|
import selenium_lib
|
2023-12-02 14:13:38 -05:00
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
|
|
|
|
|
|
|
2024-07-07 02:58:38 -04:00
|
|
|
def fill_parser(parser):
|
|
|
|
|
group_login = parser.add_argument_group(title="Login")
|
|
|
|
|
group_login.add_argument(
|
2024-05-03 23:37:09 -04:00
|
|
|
"--open_dashboard",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Open application Board.",
|
|
|
|
|
)
|
2024-07-07 02:58:38 -04:00
|
|
|
group_login.add_argument(
|
|
|
|
|
"--default_email_auth",
|
|
|
|
|
default="admin",
|
|
|
|
|
help="Email to use to authenticate with admin.",
|
2024-01-04 23:50:42 -05:00
|
|
|
)
|
2024-07-07 02:58:38 -04:00
|
|
|
group_login.add_argument(
|
|
|
|
|
"--default_password_auth",
|
|
|
|
|
default="admin",
|
|
|
|
|
help="Password to use to authenticate with admin.",
|
2024-02-06 23:27:34 -05:00
|
|
|
)
|
2024-01-04 23:50:42 -05:00
|
|
|
|
|
|
|
|
|
2024-07-07 02:58:38 -04:00
|
|
|
def run(config, selenium_tool):
|
2024-01-04 23:50:42 -05:00
|
|
|
# Trouvez les éléments du formulaire
|
2024-07-07 02:58:38 -04:00
|
|
|
courriel_input = selenium_tool.driver.find_element(By.NAME, "login")
|
|
|
|
|
mot_de_passe_input = selenium_tool.driver.find_element(By.NAME, "password")
|
2025-01-22 03:09:46 -05:00
|
|
|
div_connexion_button = selenium_tool.driver.find_element(
|
|
|
|
|
By.CLASS_NAME, "oe_login_buttons"
|
|
|
|
|
)
|
|
|
|
|
connexion_button = div_connexion_button.find_element(
|
|
|
|
|
By.CLASS_NAME, "btn-primary"
|
|
|
|
|
)
|
|
|
|
|
# try:
|
|
|
|
|
# connexion_button = selenium_tool.driver.find_element(
|
|
|
|
|
# By.XPATH,
|
|
|
|
|
# "/html/body/div/div/div/form/div[3]/button",
|
|
|
|
|
# # '//button[contains(text(), "Log in")]'
|
|
|
|
|
# )
|
|
|
|
|
# except Exception:
|
|
|
|
|
# connexion_button = selenium_tool.driver.find_element(
|
|
|
|
|
# By.XPATH,
|
|
|
|
|
# "/html/body/div/main/div/form/div[3]/button",
|
|
|
|
|
# # '//button[contains(text(), "Connexion")]'
|
|
|
|
|
# )
|
2024-01-04 23:50:42 -05:00
|
|
|
|
|
|
|
|
# Remplissez le courriel et le mot de passe
|
2024-07-07 02:58:38 -04:00
|
|
|
courriel_input.send_keys(config.default_email_auth)
|
|
|
|
|
mot_de_passe_input.send_keys(config.default_password_auth)
|
2024-01-04 23:50:42 -05:00
|
|
|
|
|
|
|
|
# Cliquez sur le bouton "Connexion"
|
2024-07-07 02:58:38 -04:00
|
|
|
try:
|
|
|
|
|
connexion_button.click()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
if (
|
|
|
|
|
'class="modal o_technical_modal show modal_shown"> obscures it'
|
|
|
|
|
in str(e)
|
|
|
|
|
):
|
|
|
|
|
# Click it
|
|
|
|
|
# xpath_button = "//div[hasclass('o_technical_modal')]/div/div/footer/button"
|
|
|
|
|
xpath_button = (
|
|
|
|
|
"//div[contains(@class,"
|
|
|
|
|
" 'o_technical_modal')]/div/div/footer/button"
|
|
|
|
|
)
|
|
|
|
|
error_button = selenium_tool.driver.find_element(
|
|
|
|
|
By.XPATH, xpath_button
|
|
|
|
|
)
|
|
|
|
|
error_button.click()
|
|
|
|
|
|
|
|
|
|
# Remplissez le courriel et le mot de passe
|
|
|
|
|
courriel_input.send_keys(config.default_email_auth)
|
|
|
|
|
mot_de_passe_input.send_keys(config.default_password_auth)
|
|
|
|
|
|
|
|
|
|
connexion_button.click()
|
|
|
|
|
else:
|
|
|
|
|
raise e
|
2024-01-04 23:50:42 -05:00
|
|
|
|
|
|
|
|
# Attendez que l'élément soit cliquable
|
2024-07-07 02:58:38 -04:00
|
|
|
# wait = WebDriverWait(selenium_tool.driver, 5)
|
2024-01-04 23:50:42 -05:00
|
|
|
# menu_toggle = wait.until(
|
|
|
|
|
# EC.element_to_be_clickable((By.XPATH, "/html/body/header/nav/ul[1]/li/a"))
|
|
|
|
|
# )
|
|
|
|
|
#
|
|
|
|
|
# # Cliquez sur l'élément
|
|
|
|
|
# menu_toggle.click()
|
|
|
|
|
#
|
|
|
|
|
# # Attendez que le lien soit cliquable
|
|
|
|
|
# menu_item = wait.until(
|
|
|
|
|
# EC.element_to_be_clickable(
|
|
|
|
|
# (
|
|
|
|
|
# By.XPATH,
|
|
|
|
|
# "/html/body/header/nav/ul[1]/li/div/a[2]",
|
|
|
|
|
# )
|
|
|
|
|
# )
|
|
|
|
|
# )
|
|
|
|
|
|
2024-05-03 23:37:09 -04:00
|
|
|
# Remove chatbot if open, because will crash wizard div[4] (to div[5])
|
2024-07-07 02:58:38 -04:00
|
|
|
selenium_tool.check_bot_chat_and_close()
|
2024-05-03 23:37:09 -04:00
|
|
|
|
2024-01-04 23:50:42 -05:00
|
|
|
# Open View
|
2024-07-07 02:58:38 -04:00
|
|
|
if config.open_dashboard:
|
|
|
|
|
selenium_tool.click(
|
2024-05-03 23:37:09 -04:00
|
|
|
"/html/body/header/nav/div/div[1]/div[2]/div/div/div/ul/li[3]/a",
|
2023-12-02 14:13:56 -05:00
|
|
|
timeout=15,
|
2024-05-03 23:37:09 -04:00
|
|
|
)
|
2024-01-04 23:50:42 -05:00
|
|
|
|
|
|
|
|
# Open conversation chat
|
2024-07-07 02:58:38 -04:00
|
|
|
# conversation_button = selenium_tool.driver.find_element(By.XPATH, '/html/body/header/nav/ul[3]/li[2]/a')
|
2024-01-04 23:50:42 -05:00
|
|
|
# conversation_button.click()
|
|
|
|
|
|
|
|
|
|
# Close bot chat
|
2024-07-07 02:58:38 -04:00
|
|
|
# conversation_button = selenium_tool.driver.find_element(By.XPATH, '/html/body/div[3]/div[1]/span[2]/a[2]')
|
2024-01-04 23:50:42 -05:00
|
|
|
# conversation_button.click()
|
|
|
|
|
|
|
|
|
|
# Fermez le navigateur
|
2024-07-07 02:58:38 -04:00
|
|
|
# selenium_tool.driver.quit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def compute_args(args):
|
|
|
|
|
pass
|
2024-01-04 23:50:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2024-07-07 02:58:38 -04:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
|
|
description="""Selenium script to open web browser to ERPLibre.""",
|
|
|
|
|
epilog="""\
|
|
|
|
|
""",
|
|
|
|
|
)
|
|
|
|
|
# Generate parser
|
|
|
|
|
selenium_lib.fill_parser(parser)
|
|
|
|
|
fill_parser(parser)
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
compute_args(args)
|
|
|
|
|
# Instance selenium tool
|
|
|
|
|
selenium_tool = selenium_lib.SeleniumLib(args)
|
|
|
|
|
selenium_tool.configure()
|
|
|
|
|
selenium_tool.start_record()
|
|
|
|
|
# Execute
|
|
|
|
|
run(args, selenium_tool)
|
|
|
|
|
selenium_tool.stop_record()
|
2024-01-04 23:50:42 -05:00
|
|
|
return 0
|
2023-12-02 14:13:38 -05:00
|
|
|
|
|
|
|
|
|
2024-01-04 23:50:42 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
sys.exit(main())
|