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

Question:

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:ChromeDriverExtractedchromedriver")
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()
Asked By: NikaTheKilla

||

Answers:

It’s a tuple you should pass there,

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

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:ChromeDriverExtractedchromedriver") 

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:ChromeDriverExtractedchromedriver.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:

Answered By: undetected Selenium

I think the key point maybe, the contents By.XPATH, "//type[@name=’RESULT_RadioButton-7_0′]" should be enclosed in parentheses and have 2 ahead and 3 after the content.

Answered By: darine 2010

Yes, it’s the structure of the Selenium that makes it very Particular. Check parentheses ((By.XPATH, "//type[@name=’RESULT_RadioButton-7_0′]")))

Answered By: Aleksandr Kulikov