Skip to content Skip to sidebar Skip to footer

Selenium - Cannot Click On Hidden Element

I am working with Selenium and Python. I am struggling to use the click() method in order to click a dynamically created radio button. The markup for the radio is below.

Solution 1:

try explicit condition to wait for the element to be displayed. (if it is time-related issue, i.e., takes time to display)

 element = WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.XPATH, "//*[@id='radio_1']"))
 element.click()

This waits up to 10 seconds before throwing a TimeoutException or if it is present on the DOM of a page and visible, will return it in 0 - 10 seconds. WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns successfully. A successful return is for ExpectedCondition type is Boolean return true or not null return value for all other ExpectedCondition types.

Reference:

  1. https://seleniumhq.github.io/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html#selenium.webdriver.support.expected_conditions.visibility_of_element_located
  2. http://selenium-python.readthedocs.io/waits.html

Solution 2:

C#

You can use waiter to element to become visible like this:

var element = Waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("ID"))).FirstOrDefault();

Post a Comment for "Selenium - Cannot Click On Hidden Element"