Search code examples
pythonseleniumselenium-webdriverwebdriverwaitexpected-condition

Takes 1 positional argument but 2 were given error using Selenium Python


Hello I was trying to click on button male on website: https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407 But it gives me the error:

TypeError: element_to_be_clickable() takes 1 positional argument but 2 were given.

The code is

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC


driver=webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver")
driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")

WebDriverWait(driver, 2).until(EC.element_to_be_clickable(By.XPATH, "//type[@name='RESULT_RadioButton-7_0']")).click()

Solution

  • You need to pass a tuple within element_to_be_clickable() as follows:

    EC.element_to_be_clickable((By.XPATH, "//type[@name='RESULT_RadioButton-7_0']"))
    

    However, your working line of code will be:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='RESULT_RadioButton-7_0']"))).click()
    

    Browser Snapshot:

    Male


    Moreover, with the following line:

    webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver") 
    

    is now associated with a DeprecationWarning as follows:

    DeprecationWarning: executable_path has been deprecated, please pass in a Service object
    

    So you need to pass an instance of Service class as an argument and your effective code block will be:

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    s = Service('D:\ChromeDriverExtracted\chromedriver.exe')
    driver = webdriver.Chrome(service=s)
    driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='RESULT_RadioButton-7_0']"))).click()
    

    References

    You can find a couple of relevant detailed discussions in: