Я использую пакет python для селена, чтобы я мог войти в свой маршрутизатор и изменить пароль, просто запустив скрипт. Я смог использовать навигацию до страницы, чтобы ввести новый пароль, где я получаю сообщение об ошибке.
Я пытался использовать оба значения для и также получить доступ через элементы таблицы.
#using chrome to access web
driver = webdriver.Chrome()
driver.get('https://192.168.100.1/')
#find the username box and send value
driver.find_element_by_id('txt_Username').send_keys('root')
#find the password box and send value
driver.find_element_by_id('txt_Password').send_keys('@Idontlike5')
#click login button
driver.find_element_by_id('loginbutton').click()
#select advanced tab
driver.find_element_by_id('addconfig').click()
#select WLAN
driver.find_element_by_id('wlanconfig').click()
#input new password
wpa2 = driver.find_element_id('wlWpaPsk')
wpa2.clear()
wpa2.send_keys('21Savage')
#select 5g wlan
#wlan5g = driver.find_element_by_id('wlan5basic')
#click apply btn
apply = driver.find_element_by_id('btnApplySubmit')
apply.click()
Идентификатор для ввода нового пароля должен быть правильным, но возвращает только ошибку.
Я получаю эту ошибку в конце
Traceback (most recent call last):
File "/home/vans/Desktop/coding/y-fi??/net.py", line 37, in <module>
wpa2 = driver.find_element_by_id('twlWpaPsk')
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
'value': value})['value']
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="wlWpaPsk"]"}
и фрагмент страницы источника
<td class="table_right">
<input type="password" autocomplete="off" id="wlWpaPsk" name="wlWpaPsk" size="20" maxlength="64" class="amp_font" onchange="wpapskpassword=getValue('wlWpaPsk');getElById('twlWpaPsk').value=wpapskpassword;" title="The password is suggested to contain at least two of the following combinations: digits, uppercase letters, lowercase letters, and special characters.">
<input type="text" autocomplete="off" id="twlWpaPsk" name="twlWpaPsk" size="20" maxlength="64" class="amp_font" style="display:none" onchange="wpapskpassword=getValue('twlWpaPsk');getElById('wlWpaPsk').value=wpapskpassword;" title="The password is suggested to contain at least two of the following combinations: digits, uppercase letters, lowercase letters, and special characters.">
<input checked="" type="checkbox" id="hidewlWpaPsk" name="hidewlWpaPsk" value="on" onclick="ShowOrHideText('hidewlWpaPsk', 'wlWpaPsk', 'twlWpaPsk', wpapskpassword);">
<script>document.write(cfg_wlancfgdetail_language['amp_wlanpassword_hide']);</script>Hide
<font class="color_red">*</font><span class="gray">
<script>
document.write(cfg_wlancfgdetail_language['amp_wpa_psknote' + ('1' == kppUsedFlag ? '_63' : '')]);
</script>(8-63 characters or 64 hexadecimal characters)</span>
<span class="gray" id="pskpasswordwarning" style="display:none;"></span></td>