Search code examples
pythonseleniumxpathcss-selectorsselenium4

How to click on an input element using Selenium and Python


I'm trying to click on the tab with text as Python within the Selenium documentation website.

HTML:

<input type="radio" name="tabsetcode2" id="tab1code2" aria-controls="pythoncode2">

But I'm facing TimeoutException:

selenium.common.exceptions.TimeoutException: Message:

Code trials:

driver.get('https://www.selenium.dev/documentation/en/')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[aria-controls='pythoncode2']"))).click()

Can anyone help me out to click on the Python tab?


Solution

  • You can click on the label instead and it works.

    driver.get('https://www.selenium.dev/documentation/en/')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='tab1code2']"))).click()