How do I find the selenium element's invisibility, if its already assigned to a variable

35 views Asked by At

First I have a code that finds the element :

    @property
    def tools_button(self):
        driver: WebDriver = current().context.driver
        return driver.find_element(
            SelectBy.XPATH, f"//button[contains(text(),'Tools')]"
        )
--------------------------------------------------------------------
       tools_button = locators.tools_button

this tools button is in a modal that disappears after I click the Close Button.

My question is, how do i find element's invisibility similar to what this code does:

wait.until(
            ui.EC.invisibility_of_element_located(
                (SelectBy.XPATH, "//button[contains(text(),'Tools')]")
            )
        )

I need to check if the modal was closed or not, by checking the invisibility of the Tools Button in that modal.

But I need to find the Tools Button without having to pass the xpath and "by" again. is there a way to extract those two attributes from the already found element? or is there some special way to provide the invisibility_of_element_located function whole element.

1

There are 1 answers

1
Mahboob Nur On

You can use the invisibility_of expected condition along with the WebElement directly, without passing the locator again. Here's how you can achieve it

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

# Assuming `tools_button` is the WebElement you've already found
tools_button = locators.tools_button

# Wait for the element to become invisible
wait = WebDriverWait(driver, timeout)
wait.until(EC.invisibility_of(tools_button))