Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 571
NikaTheKilla Avatar asked May 03 '26 08:05

NikaTheKilla


2 Answers

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 selenium4 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:

  • init() takes 2 positional arguments but 3 were given using WebDriverWait and expected_conditions as element_to_be_clickable with Selenium Python
  • Use Selenium with Brave Browser pass service object written in python
like image 148
undetected Selenium Avatar answered May 04 '26 22:05

undetected Selenium


It's a tuple you should pass there,

EC.element_to_be_clickable((By.XPATH, "//type[@name='RESULT_RadioButton-7_0']")))
like image 24
Aghil Varghese Avatar answered May 04 '26 22:05

Aghil Varghese