When the location of some elements is not convenient, you can use find elementsto locate them
1. When a group of elements have the same attributes, find﹣elements is used to obtain a group of elements. By looping the group of elements, locate the elements by corresponding text or element attribute values. For example:
(keystrtext: attributename=) -> WebElement: dic = ReadyamlToElement(.__driver.__yamlPath).__getAllValue() list_keyelements = [] key dic: list_value = dic.get(key) list_Type_value = list_value.get() list_Value_value = list_value.get() list_keyelements = FindWebElement(.__driverlist_Type_valuelist_Value_value).find_elements(.__yamlPathkey) Primary.Log.info(.__yamlPath + + key) : Primary.Log.warning(.__yamlPath + + key + ) booleanfind = element = attributename : webelement list_keyelements: webelement.text == strtext: element = webelement booleanfind = : webelement list_keyelements: webelement.get_attribute(attributename) == strtext: element = webelement booleanfind = booleanfind: element : Primary.Log.warning(.__yamlPath + + strtext + ) element
2. Some elements will appear in the pop-up page, disappear when the pop-up window is closed, or appear when the tab is clicked, but the style of the element is the same as other elements, and the positioning method is very troublesome. It is mainly found in some elements with role=tabs, or table forms. You can judge the element by judging the number of elements
For example, a new table form will appear after clicking the corresponding button, that is, you can locate it by judging the number of the table forms; the form whose class is ant table can appear after clicking the buttons of by day, by month and by year, which is judged by the number
(list_tabs) - list_tabs_num == : list_date = [] j (-): list_tabs[j].click() ant_table_tbody_element_now = .__water_electricity__yaml.getelements() (ant_table_tbody_element_now) == ant_table_tbody_num_old + : time.sleep() tbody_element = ant_table_tbody_element_now[-] run_date = .__check_exact_data(tbody_element) ant_table_tbody_num_old = (ant_table_tbody_element_now) list_date.append(run_date)
3. Add interface operation in UI automation, and locate elements after the interface returns successfully. It is mainly used to prevent the value front-end style of some elements from loading faster than the interface, resulting in the situation that it is empty