Selenium is a tool to test web-pages. Modern web-pages have become very complicated with numerous stacks of pages and hundreds of links. Manual testing is tedious and error prone. Having a scripted test ensures that all elements of the web-page are tested in a repeatable fashion.
Selenium has been successfully testing web-pages since 2004. Selenium 2.0 arrived in 2011, 3.0 in 2016 and Selenium 4.0 was released in 2019. Selenium 4 has the usual bug fixes and feature requests. The Selenium Suite of tools consists of the Selenium IDE, Webdriver, Grid/Hub and Selenium Side Runner. Selenium IDE uses a typical test approach called record and playback to build test suites following a manual test plan. Selenium RC is now called Selenium WebDriver. RC stood for Remote Control which is what it did, execute commands like a real user. Webdriver is a replacement name for RC. It does the same user automation for five programming languages and is supported by common browsers. WebDriver knows how to talk directly to the browser software. WebDriver can even be headless, meaning there is no browser at all. The commands go directly to the Web-server without seeing the commands run on a browser. Grid along with the Selenium Hub allow several test clients to run in parallel in multiple formats and locations so you can scale your testing. This article and my other articles are about Selenium 4 enhancements to Webdriver. Generally Webdriver is a solution to test features that previously had to be tested manually or were difficult to automate. The new Selenium 4 feature, Action Chains Action as the name implies movement and key actions. Action chains are mouse pointer movements and mouse clicks. Keyboard presses are also supported. They are chains since you need to move to an element, click the the mouse or type some key(s) and then add perform(). Nothing happens without the perform() function at the end.
Find, move, do something Part of testing web-page is the ability to move around the page using the mouse and sometimes keyboard input. Web-page elements identified with tags, are located at specific x,y coordinates on the web-page. These coordinates will change as the page is resized. The browser software is responsible for placing and sizing the visible elements at x,y coordinates and calculate the height and width of the element. Test automation can’t move to elements without first identifying the element and size/location of the element from the browser. It’s a two step process, first identify the element by it’s ID, CSS_SELECTOR, TAG_NAME, XPATH or CLASS_NAME. With the identifier, you can ask the browser where it is and how big it is. There is a work around to finding the element. You may use x,y coordinates to “move” to any location in the page. There is a limitation to this method of relocating since the whole web-page can be resized and all the x,y coordinates change. Generically these commands are called “gestures” The command most often looks like this searchBtn = driver.find_element(By.LINK_TEXT, “Sign in”) webdriver.ActionChains(driver).context_click(searchBtn).perform() This is a chain of commands or another name for it is “composite command”. The available methods are below. In most cases, the element has to be found first with the find_element function. Clicks
click(el=None) click on the element or current location click_and_hold(el=None) click and hold button on location context_click(el=None) context click means right click double_click(el=None) Drag, Drop drag_drop(source, target) drag_and_drop_by_offset(source,x,y) hold down left mouse move to target then release Key push key_down(key, el=None) down only key_up(key, el=None) send_keys(keys) send_key_to_element(el, x, y) send keys inside element Move mouse move_by_offset(x,y) move mouse by x,y move_to_element(el) move mouse to center of element move_to_element_with_offset(el,x,y) move mouse then x,y offset from top left Misc. pause(sec) wait for seconds same as time.sleep() perform() perform stored action release(el = None) release held mouse buttons reset_actions() clear stored actions Notes
The command(s) are queued and do not execute until the perform() command is run. The left mouse button is the primary or default button
The right mouse button is know as the context mouse button. It reveals a contextual menu , shortcut menu or pop-up menu.