1

The question on the survey asks: What days of the week are you consistently available? I would like to check Sunday.

I am duplicating the code I see from an online video, however, I am receiving this error. Some people are suggesting that a pop-up may be blocking the program from working correctly but I do not see a pop up.

I have tried using chromedriver and geckodriver. The error is present in both.

The code to see if Sunday is selected works properly:

status=driver.find_element_by_id("RESULT_CheckBox-8_0").is_selected()
print(status) 

output:

False

Here is my code:

from selenium import webdriver 

driver=webdriver.Chrome(executable_path="my_webdriver_path"\\chromedriver.exe

driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")

What days of the week are you consistently available?

I would now like to check the Sunday box. Here is my code:

status=driver.find_element_by_id("RESULT_CheckBox-8_0").click()
    print(status)

I would like the Sunday box checked but I am receiving this error:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <input id="RESULT_CheckBox-8_0" class="multiple_choice" name="RESULT_CheckBox-8" type="checkbox"> is not clickable at point (313,599) because another element <label> obscures it

I do not see another element that obscures the program. Does anyone have any suggestions? I am new to coding so any help would be greatly appreciated.

Able Archer
  • 421
  • 4
  • 13
  • Text `Sunday` is a label for this checkbox and it may hide checkbox so it is not clickable. You could try to click this label – furas Sep 11 '19 at 06:19

3 Answers3

2

The problem you're having is related to the same values that are being used for different attributes in the label and input tags.

As you can see the 'for' attribute of the label has the same value as the 'id' attribute (wich doesn't allways have to be a unique value) of the eventhough you are using 'find_element_by_id'.

To fix this you could use a different locator like XPATH. You can get a xpath by right clicking on the element (when you are inspecting the code with f12) and than select [copy] - [xpath]

Here is some code that should work (note: I have placed the chromedriver.exe in the same location as the .py file it self):

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407')
status = driver.find_element_by_id("RESULT_CheckBox-8_0").is_selected()

if status:
    pass
else:
    driver.find_element_by_xpath("//*[@id='q15']/table/tbody/tr/td[1]/label").click()

Don't forget to eventually close the driver, otherwise it will stay in de background as a running procces.

You can do so by:

driver.close()

Hope this helps!

Ewald
  • 122
  • 5
2

Try use ActionChains to click the element.

element = driver.find_element_by_id("RESULT_CheckBox-8_0")
ActionChains(driver).move_to_element(element).click(element).perform()
status = driver.find_element_by_id("RESULT_CheckBox-8_0").is_selected()
print(status)

Following import:

from selenium.webdriver import ActionChains
frianH
  • 5,901
  • 6
  • 13
  • 36
2

To click() on the checkbox with text as Sunday you can use the following Locator Strategy:

  • Using XPATH:

    driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'RESULT_CheckBox-') and contains(., 'Sunday')]"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

Sunday

DebanjanB
  • 118,661
  • 30
  • 168
  • 217