11/09/2021 | News release | Distributed by Public on 11/09/2021 12:22
Find the code sample for this project on DevNet Code Exchange
Selenium is an open-source tool that automates web browsers. It provides a single interface that lets testers automate user actions using multiple programming languages such as Ruby, Java, NodeJS, PHP, Perl, Python, and C#. But what if we try to automate some tasks that we can do only by using Web GUI interfaces/Dashboard? Let's check it out.
Some of the described examples were born from customers' requests when we found out that related features in the chosen license type are unavailable. We identified issues that we can't solve using API or CLI. For example, if we have a particular graphical web interface and related items that users can configure, we can automate this process by using a tool like Selenium that automates web browsers.
In the sample, you can see how we automatically add (from the list) VPN exclusion rules after running the script.
Using the methods below, the Web browser can find the first element on an HTML page with related parameters. Elements were chosen from different Cisco Web interfaces.
Find one element with examples.
Method with parameter |
This can find the element |
find_element_by_id("__dnaPlatformHeaderLeft") | <div id="__dnaPlatformHeaderLeft"></div> |
find_element_by_name("leaf_name") | <input name="leaf_name" type="text" /> |
find_element_by_xpath("//input[@placeholder='192.168.0.0/24′]") | <input class="flex-item cidr_input" type="text" placeholder="192.168.0.0/24″> |
find_element_by_link_text("Topology") | <a href="/topology">Topology</a> |
find_element_by_partial_link_text("event") | <a href="/manage/dashboard/event_log?c=00%3A0x%3A23%3A36%3A01%3Ad9″ target="_blank" rel="noopener noreferrer">event log</a> |
find_element_by_tag_name("h1") | <h1>DHCP</h1> |
find_element_by_class_name("dst_port") | <input class="dst_port" placeholder="Any" size="4″> |
find_element_by_css_selector("button.LabeledToggle__button") | <button type="button" class="LabeledToggle__button">VLANs</button> |
If you need to find a few elements - use the method find_elements.
If on the target page your target element doesn't have a unique CSS class or id - you can use find_element_by_xpath.
If you want to find an element by specific tag and parameter driver - use find_element_by_xpath("//input[@class='dst_port']")
Potential threats for automation scripts (using Selenium or similar tools)
The reasons mentioned above can lead to incorrect execution of the automated script.
If changes affect HTML parameters like id, class (your script can't find related elements).
Here are some potential errors you might get:
Tips and fast tracks to write stable script/app:
Tasks and scenarios for which you can use Selenium or similar tools
Summary
You can use Selenium for the configuration or management of your devices and solutions with a GUI interface. To be honest, it's an experimental approach. Firstly, you need to recognize whether you can solve your problem by using API/CLI, in case not, you can use this using a browser, then Selenium is a solution just for you. If you have a repeatable task that is connected with your web interface, and you usually solve it by using a browser, Selenium is a reasonable means for you.
Related resources
Share: