skip to content

Element Interaction

What you can actually do to an element once you hold it: click it, type into it, read its state, drive it with low-level input, and read the exception when the command cannot land.

on this pageshow

explore

questions

page 2 of 2

In Selenium, why does a loop over a cached List of WebElement rows start failing part-way through?

level: seniorimportance: should knowfreq 46%

basics

~20 s

The list is a snapshot of references captured at one instant, not a live view. If the loop body changes the page, the rows it replaces are detached and every remaining handle in the list is dead.

open as a page

Your Selenium upload tests must run against a local browser and a remote browser with its own filesystem - how would you design for both?

level: principalimportance: should knowfreq 32%

basics

~20 s

Hold one invariant: the file must exist where the browser can read it. Keep the test bodies identical, and put the difference in session creation, where a remote driver gets a LocalFileDetector and a local driver keeps the default.

open as a page

In Selenium, how do Actions.scrollToElement() and Actions.scrollByAmount() differ, and which device do they drive?

level: juniorimportance: nice to knowfreq 31%

basics

~20 s

Both drive Selenium's virtual wheel device, added in Selenium 4.2. scrollToElement takes an element and scrolls it into view, letting the driver work out the distance; scrollByAmount takes pixel deltas from the viewport's top left corner.

open as a page

In Selenium, what does the strictFileInteractability capability change for a hidden input type=file?

level: middleimportance: nice to knowfreq 27%

basics

~20 s

It turns the interactability checks back on for file inputs. Selenium 4 defaults it to false, so a path can be sent to a hidden file input; set it to true and that same element is rejected as not interactable.

open as a page

In Selenium, how does a script run by executeAsyncScript signal completion, and what happens if it never signals?

level: middleimportance: nice to knowfreq 34%

basics

~20 s

Selenium appends a callback as the script's last argument, so the script calls arguments[arguments.length - 1] with its result. If it never calls back, the command blocks until the script timeout elapses and then throws ScriptTimeoutException.

open as a page

What does Selenium's WebElement.getAriaRole() return, and how does it differ from reading the role attribute?

level: seniorimportance: nice to knowfreq 21%

basics

~20 s

It returns the WAI-ARIA role the browser computed for the element, including the implicit role of the tag. Reading the role attribute returns only the literal token the markup declared, or nothing when the markup declared none.

open as a page

showing 31–36 of 36