diff --git a/tests/fixtures/ui.py b/tests/fixtures/ui.py index eb2304602..d72a29e8d 100644 --- a/tests/fixtures/ui.py +++ b/tests/fixtures/ui.py @@ -99,6 +99,19 @@ def select(self, selector): def select_all(self, selector): return self.webdriver.find_elements(by=By.CSS_SELECTOR, value=selector) + def by_text(self, text, tag_name="*"): + """Helper to select an element with the text it contains. + The element tag can also be provided, to be more explicit. + + Example: + + can be selected with: by_text("Click me", "button") + """ + + return self.webdriver.find_element( + By.XPATH, f"//{tag_name}[contains(text(), {text!r})]" + ) + def list_download_filenames(self): self.webdriver.command_executor._commands["SET_CONTEXT"] = ( "POST", diff --git a/tests/test_20_inventory.py b/tests/test_20_inventory.py index 57553475f..a835525e2 100644 --- a/tests/test_20_inventory.py +++ b/tests/test_20_inventory.py @@ -93,7 +93,7 @@ def test_edit_instance(registered_agent, browser, ui_url): comment = browser.select("#inputCommentUpdate").get_attribute("value") assert "Registered by tests." == comment Select(browser.select("#selectEnvironmentUpdate")).select_by_visible_text("default") - browser.select("#buttonSubmitUpdate").click() + browser.by_text("Update", "button").click() def test_download_inventory(registered_agent, browser):