nonSuchElementException in toggling the checkbox of editor

when command for unchecking the checkbox of toggle editor is executed ,error occurs

hey @stutijain578 ,
Sometimes it happen is the element we want to select is out of the window and selenium doesn’t finds it.
So , just a try scroll down to that element and then select. To scroll , search about this for selenium on internet.

if still it doesn’t works , then you might be providing the wrong element id to get your element , then check that once.

I hope it helps.

it is not working even on scrolling and id is also correct

hey @stutijain578 ,
can you please provide me link to your code , so that i can give it a try and check what actually the problem you are stuck at.

import time
from selenium import webdriver
from selenium.webdriver.support import expected_conditions

browser=webdriver.Chrome("/Users/stutijain/Downloads/chromedriver")
browser.get(“https://codechef.com”)
username_element=browser.find_element_by_id(“edit-name”)
username_element.send_keys(“stutijain578”)
password_element=browser.find_element_by_id(“edit-pass”)
from getpass import getpass
password_element.send_keys(getpass(“enterpassword”))
browser.find_element_by_id(“edit-submit”).click()
with open("/Users/stutijain/Downloads/Ide.cpp",‘r’) as f:
code=f.read()

browser.get(“https://www.codechef.com/submit/START01”)

browser.execute_script(“window.scrollTo(0, 800)”)

try:

browser.find_element_by_id(“edit_area_toggle_checkbox_edit-program”).click()

except:

print(“sorry bro! not found this damn id”)

browser.execute_script(“window.scrollTo(0, 500)”)

program = browser.find_element_by_id(“edit-program”)

program.send_keys(code)

# browser.find_element_by_xpath(’//*[@id=“edit-language”]/option[1]’)

time.sleep(5)
browser.find_element_by_id(“edit-submit”).click()

time.sleep(10)
browser.execute_script(“window.scrollTo(0, 700)”)
time.sleep(5)

browser.find_element_by_id(“edit_area_toggle_checkbox_edit-program”).click()

browser.find_element_by_xpath(’//[@id=“edit_area_toggle_checkbox_edit-program”]’).click()
time.sleep(10)
browser.find_element_by_xpath(’//
[@id=“edit-language”]/option[1]’).click()
#If internet connection is slow, uncomment next line
time.sleep(10)

browser.execute_script(“window.scrollTo(0, 500)”)
prog_input=browser.find_element_by_id(“edit-program”)
prog_input.send_keys(code)

#If internet connection is slow, uncomment next line
time.sleep(10)

browser.execute_script(“window.scrollTo(0, 600)”)

browser.find_element_by_id(“edit-submit-1”).click()

hey @stutijain578 ,
i just ran your code by making slight changes based on this code and it ran absolutely fine.

Have a look at this and let me know , if you get stucked somewhere.

What i found in your code is , your scrolling is not working properly and hence it is unable to click the required toggle option.

can you please explain the new commands in the code you shared which were not taught by Mohit bhaiya ?

hey @stutijain578 ,
before i explain you about that work, kindly try it once by yourself .
Search about them on google , implement them , and experiment them . If still stucked then i will surely help you out.

Our Goal is to help you learn and understand.
So once try them.

in line 28 whose xpath have you mentioned ?

i wanted to get the toggle button to be in between the window. So i just did that manually first and took the bottom element xpath and used that in automation.
so its that.
You can change it too , there is no problem in that.