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()
CodePudding user response:
It's a tuple you should pass there,
EC.element_to_be_clickable((By.XPATH, "//type[@name='RESULT_RadioButton-7_0']")))
CodePudding user response:
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']"))
So your working line of code will be:
WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, "//type[@name='RESULT_RadioButton-7_0']"))).click()
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, 2).until(EC.element_to_be_clickable((By.XPATH, "//type[@name='RESULT_RadioButton-7_0']"))).click()
References
You can find a couple of relevant detailed discussions in: