Selenium hittar inte element, python
Så jag försöker att klicka i en checkbox, men selenium hittar inte elementet och får felmeddelande att den inte hittar.
Jag vet all information, men tydligen så har Selenium svår att hitta vissa saker.
Jag vet,
<input type="checkbox" id="chkSsh" name="chkSsh" class=" checkbox">
chkSsh
html body form#mainPageForm table tbody tr td table tbody tr td.formBody table tbody tr#trSsh td.ctrlSpacing table#Table1 tbody tr td input#chkSsh.checkbox
/*[@id="chkSsh"]
Men från vad jag har läst så måste man byta något fönster på sidan då Selenium inte läser allt.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import ElementClickInterceptedException
from selenium.webdriver.common.action_chains import ActionChains
import time
user_name = "root"
password = "root"
driver = webdriver.Firefox(executable_path=r'C:\geckodriver.exe')
driver.get("http://192.168.1.254")
element = driver.find_element_by_id("userName$query")
element.send_keys(user_name)
element = driver.find_element_by_id("password")
element.send_keys(password)
element.send_keys(Keys.RETURN)
for i in range(20):
try:
element = driver.find_element_by_id("1660").click()
break
except (NoSuchElementException, ElementClickInterceptedException):
time.sleep(1)
time.sleep(2)
for i in range(10):
try:
element = driver.find_element_by_id("chkSsh").click()
break
except (NoSuchElementException, ElementClickInterceptedException):
time.sleep(1)
Så jag loggar in och öppnar i ett drop down meny, sedan så försöker jag trycka på "chkSsh" lådan, men får felmeddelande att den inte finns, om jag hämtar alla element på sidan så finns det inte.
Är det någon som vet hur man gör? Typ om jag skulle vilja trycka i denna låda.