2

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()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
NikaTheKilla
  • 115
  • 2
  • 11
  • Ok.Found the answer just wrote ``` driver.find_element_by_xpath("//*[@id='q26']/table/tbody/tr[1]/td/label").click() ``` – NikaTheKilla Nov 20 '21 at 16:22

4 Answers4

4

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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • It gives me this error and It doesn't click it Error: Traceback (most recent call last): File "C:\Users\Puhceto\SeleniumProject\venv\Clicking A Button.py", line 10, in WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, "//type[@name='RESULT_RadioButton-7_0']"))).click() – NikaTheKilla Nov 20 '21 at 16:06
  • @NikaTheKilla Checkout the updated answer and let me know the status. – undetected Selenium Nov 20 '21 at 16:19
1

It's a tuple you should pass there,

EC.element_to_be_clickable((By.XPATH, "//type[@name='RESULT_RadioButton-7_0']")))
Aghil Varghese
  • 360
  • 1
  • 10
  • It didn't click the button. Error DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver=webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver") – NikaTheKilla Nov 19 '21 at 18:08
  • @NikaTheKilla This issue is appearing selenium, pip and python updates, check here https://stackoverflow.com/questions/64717302/deprecationwarning-executable-path-has-been-deprecated-selenium-python – Aghil Varghese Nov 19 '21 at 18:22
0

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.

-1

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