Sorting dictionary first by key, then by value

I have just completed a fun exercise on HackerRank named Company Logo. The task was to “print the three most common characters along with their occurrence count”. Task Two key conditions were: Sort in descending order of occurrence count, If the occurrence count is the same, sort the characters in alphabetical order. As with most of the problems, there is more than one solution, but because I recently explored the collections module and DefaultDict in particular, it was the first thing that came to my mind - I would insert each character into the dictionary and on each occurence increment the value by 1. ...

July 17, 2023 Â· 2 min Â· 408 words

Python's collections module

I’m currently going over Python’s collection module exercises on HackerRank. This module offers a range of data-structures and algorithms that can enhance the performance and functionality of your Python programs. What I’ve learned so far is that when I am in need of some specialized data-structure, I should take a look into collections module. Python’s collection module offers: Counter The Counter class within the collections module provides an efficient way to count the occurrence of elements in a collection. It takes an iterable as input and returns a dictionary-like object where elements are keys and their counts are the corresponding values. ...

June 6, 2023 Â· 4 min Â· 801 words

Locating Elements

[TOC] Web element interactions are at the core of web automation using Selenium and Python. By leveraging the various locator strategies available, you can precisely locate and interact with web elements. Modern websites can be very complex and unique, therefore learning different locators can be a great investment. Benefits of knowing various locator strategies: Precise Element Identification: Locators allow you to target specific elements on a web page accurately. Flexibility and Adaptability: Locators provide flexibility in locating elements by offering different strategies such as ID, class name, tag name, etc. Maintainability and Robustness: Locators help in creating maintainable and robust automation scripts. Reusability: Once you define a locator for an element, you can reuse it across multiple test cases or scenarios. Improved Readability: Locators make your automation scripts more readable and understandable. Enhanced Debugging and Troubleshooting: When an automation script encounters an issue, having well-defined locators makes debugging and troubleshooting more manageable. Cross-Browser and Platform Compatibility: Locators help ensure cross-browser and platform compatibility. Reduced Maintenance Effort: With reliable locators, your automation scripts require fewer updates and maintenance efforts. Locator strategies As mentioned before, Selenium comes with many locators, such as: ...

May 26, 2023 Â· 4 min Â· 763 words

Expected Conditions

One essential aspect of Selenium is handling synchronization issues (for example, AJAX loading screen), where the automation script needs to wait for specific conditions to be met before proceeding. This is where “Expected Conditions” come into play, providing a flexible and efficient way to wait for elements or certain states to appear or change on a web page. What are Expected Conditions? Expected Conditions are predefined conditions that Selenium can wait for, ensuring that the desired state or element is available before performing an action or assertion. These conditions are part of the selenium.webdriver.support.expected_conditions module and can be used in conjunction with the WebDriverWait class to implement effective synchronization in your automation scripts. ...

May 17, 2023 Â· 2 min Â· 350 words

Exception Handling

One of the most important features of Python is its ability to handle exceptions gracefully. Exception handling is the process of detecting and dealing with errors that occur during the execution of a program. In Python, exception handling is implemented using a combination of try, except, else, and finally blocks. Exception Handling The try block The try block is the section of code where you put the code that may raise an exception. It is essentially a “sandbox” where you can test your code for potential errors. If an exception occurs in the try block, the code execution jumps to the corresponding except block. ...

April 21, 2023 Â· 4 min Â· 656 words

Finding element with partial id in Selenium

I am currently automating some tasks with selenium and I faced a challenge where an element would render each time with a slightly different ID - the first part would be the same, but the ending would be different, such as id=navbarTop_13123. Part navbarTop_ would always be the same, but the ending different. Partial ID Selectors Partial ID selectors are a powerful feature of CSS selectors that allow you to select elements based on a partial match of their id attribute. This can be useful when the id attribute of an element contains a dynamic or changing value, and you need to select the element based on only part of the id attribute. ...

April 4, 2023 Â· 2 min Â· 237 words