-I want to operate the management screen of network devices with webdriver. -Fortigate has a RESTFUL interface, but I don't think about it this time.
-It may be possible to monitor a peculiar failure that makes it impossible to log in to the fortigate management screen.
・ Fortigate (Fortigate-60D 6.0.x this time) ・ Ubuntu 20.04 ・ Environment where selenium + firefox works (https://qiita.com/gaichi/items/1ece50111b50f8de6453)
-Install the selenium IDE plugin in Firefox and see the results recorded by record. -Search from the HTML source. Although it is a record of record, the operation may not be picked up well and different results may be obtained even with the same operation. I understand HTML somehow, but I don't understand css at all, so I searched for it quite appropriately.
#!/bin/python3
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import time
USERNAME='admin'
PASSWORD='password'
LOGINURL='https://192.168.1.99/login'
#Launch browser
options = Options()
options.binary_location = '/usr/bin/firefox'
#options.add_argument('-headless')
driver = webdriver.Firefox(options=options)
#Get Fortigate login screen
driver.get(LOGINURL)
# ID,Enter Password
time.sleep(1)
driver.find_element_by_id('username').send_keys(USERNAME)
time.sleep(1)
driver.find_element_by_id('secretkey').send_keys(PASSWORD)
time.sleep(1)
driver.find_element_by_name('login_button').click()
time.sleep(5)
#↑ It takes time to display the management screen, so wait for a long time.
#Click the Admin menu
driver.find_element_by_class_name('admin-avatar').click();
time.sleep(2)
#Click Log Out
driver.find_element_by_class_name('fa-sign-out').click();
time.sleep(10)
#Exit browser
driver.quit()
Recommended Posts