diff --git a/content/get_list_wizard_sections.json b/content/get_list_wizard_sections.json new file mode 100644 index 0000000..9445855 --- /dev/null +++ b/content/get_list_wizard_sections.json @@ -0,0 +1,4 @@ +{ + "tabmenu-item": "t3js-tabmenu-item", + "active-item": "active" +} \ No newline at end of file diff --git a/content/get_list_wizard_sections.py b/content/get_list_wizard_sections.py new file mode 100644 index 0000000..6ad6fd2 --- /dev/null +++ b/content/get_list_wizard_sections.py @@ -0,0 +1,25 @@ +import json +import os +from selenium import webdriver +from selenium.webdriver.common.by import By + + +def get_list_wizard_sections( + driver: webdriver.firefox.webdriver.WebDriver, +) -> tuple[int | None, list[str]]: + string_json_path: str = os.path.join("content", "get_list_wizard_sections.json") + + with open(string_json_path, "r") as file: + string_dict = json.load(file) + + found_element_list = driver.find_elements(By.TAG_NAME, "li") + active_element: None | int = None + labels: list[str] = [] + + for i in found_element_list: + if str(i.get_dom_attribute("class")).startswith(string_dict["tabmenu-item"]): + if str(i.get_dom_attribute("class")).find(string_dict["active-item"]) != -1: + active_element = len(labels) + labels.append(i.text) + + return active_element, labels diff --git a/content/get_list_wizard_sections_tools.py b/content/get_list_wizard_sections_tools.py new file mode 100644 index 0000000..ce5b2fa --- /dev/null +++ b/content/get_list_wizard_sections_tools.py @@ -0,0 +1,36 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By + + +def get_list_wizard_sections_tools( + driver: webdriver.firefox.webdriver.WebDriver, +) -> tuple[list[int], list[int], list[str], list[str]]: + center_x: list[int] = [] + center_y: list[int] = [] + content_name: list[str] = [] + image_name: list[str] = [] + + found_element_list = driver.find_elements(By.TAG_NAME, "div") + for i in found_element_list: + if str(i.get_dom_attribute("class")).startswith("tab-pane active"): + found_child_list = i.find_elements(By.TAG_NAME, "span") + + for j in found_child_list: + if str(j.get_dom_attribute("class")).find("t3js-icon") != -1: + content = str(j.get_dom_attribute("class")) + content = content.split(" ")[-1] + content_name.append(content) + + found_img_list = j.find_elements(By.TAG_NAME, "img") + assert len(found_img_list) == 1 + found_img = found_img_list[0] + src_info = found_img.get_dom_attribute("src") + src_info = src_info.split("/")[-1] + image_name.append(src_info) + + x = found_img.location["x"] + found_img.size["width"] // 2 + y = found_img.location["y"] + found_img.size["height"] // 2 + center_x.append(int(x)) + center_y.append(int(y)) + + return center_x, center_y, content_name, image_name diff --git a/content/set_wizard_section.py b/content/set_wizard_section.py new file mode 100644 index 0000000..d86c212 --- /dev/null +++ b/content/set_wizard_section.py @@ -0,0 +1,24 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from content.get_list_wizard_sections import get_list_wizard_sections +import time + + +def set_wizard_section( + driver: webdriver.firefox.webdriver.WebDriver, target: str | None +): + if target is None: + return + + active_element, labels = get_list_wizard_sections(driver) + while labels[active_element] != target: + found_element_list = driver.find_elements(By.TAG_NAME, "a") + for i in found_element_list: + if i.text == target: + i.click() + time.sleep(1) + break + + active_element, labels = get_list_wizard_sections(driver) + + return