'How do I click link hidden by element in selenium?

I am trying to access a link that is only available when I select a filter button element. Filter Button Desired Link

I have tried to access the element using CSS Selector, since the link text contains "include-out-of-stock".

driver.get("https://www.target.com/c/young-adult/-/N-qh1tf?Nao=0")

#Selects the filter button
link = driver.find_element(By.ID, "filterButton")
link.click()

#The code that is given me issues. It doesn't find the desired link even though it's in the html inspector
element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a[href*='include-out-of-stock']")))
element.click()

However, the element is seemingly unfound as I encounter a TimeoutException. I did play around to see if xpath would work, but I still meet the same issues. Is the element not interactable since it's not directly on the webpage? Could I just not be accessing the element right?



Solution 1:[1]

You have incorrect identifier as it has no attribute id with filtersButton. A simple xpath for that button would be

//button[@data-test='filtersButton']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arundeep Chohan