0

i am trying to make my selenium script select the "selectALL" checkbox on a website. The trouble is the python program cannot find it

I have tried

  • Using name
  • Using xpath

Results are as follows.

With name:

checkButton = driver.find_element_by_name("checkALL")
checkButton.click()

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="checkALL"]"}
  (Session info: chrome=80.0.3987.132)

With xpath:

checkButton = driver.find_element_by_xpath("//table[@id='tbl2']/tbody/tr/td/input")
checkButton.click()

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//table[@id='tbl2']/tbody/tr/td/input"}
  (Session info: chrome=80.0.3987.132)

Google Chrome element dump:

<input type="checkbox" name="checkALL" rownumber="" value="notchecked" onclick="checkAllCheckedRows('portID')">

I'm very confused as to why this is not working. I even have a 5 second delay between actions.

Full Code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
import time
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("http://192.168.1.235/login.cgi")
assert "NETGEAR ProSAFE Plus Switch" in driver.title
#Locate Password
passwordInput = driver.find_element_by_id("password")
#Input switch password
passwordInput.clear()
passwordInput.send_keys("password")
passwordInput.send_keys(Keys.RETURN)
#Wait for mainpage to load
time.sleep(5)
#Switch to Port Status
portStatusButton = driver.find_elements_by_xpath('//*[@id="blueLinkBold11"]/div[2]/a')
print(portStatusButton)
portStatusButton[0].click()
time.sleep(5)
#Check select all checkbox
checkButton = driver.find_element_by_name("checkALL")
checkButton.click()
#Select option from Menu (Disable)
speedDropdown = Select(driver.find_element_by_name("SPEED"))
speedDropdown.select_by_value(2)
#Click Apply Button
applyButton = driver.find_element_by_name("btn_Apply")
applyButton.click()
driver.close()
Guy
  • 46,488
  • 10
  • 44
  • 88
Lyra Orwell
  • 1,048
  • 4
  • 17
  • 46

2 Answers2

1

You have to switch to the right iframe before interacting with the element.

driver.switch_to.frame(driver.find_element_by_css_selector(css_selector))
# then click on the element.
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='checkALL']"))).click()
supputuri
  • 13,644
  • 2
  • 21
  • 39
  • If you feel the issue is resolved, please accept the answer and upvote for the benefit of future vistiors. – supputuri Mar 17 '20 at 17:57
0

To click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='checkALL'][value='notchecked'][onclick^='checkAllCheckedRows']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='checkALL' and @value='notchecked'][starts-with(@onclick, 'checkAllCheckedRows')]"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352