Clicking and Setting Values

JavaScript Click

WebElement placeOrder = driver.findElement(By.id("place-order"));
js.executeScript("arguments[0].click();", placeOrder);

A JavaScript click fires the click event directly. It works even when the element is covered or off screen, which is exactly why it can hide real bugs: a real user could not click a button covered by a popup.

Setting a Read-only Field

// date picker input is readonly; set it directly for a non-date-picker test
WebElement date = driver.findElement(By.id("delivery-date"));
js.executeScript("arguments[0].value = arguments[1]; arguments[0].dispatchEvent(new Event('change'));",
        date, "2026-10-28");
System.out.println(date.getDomProperty("value"));

Example

Output:

Run DeliveryDateTest.main()

Example output

2026-10-28

Tip: Fire a change or input event after setting the value, otherwise frameworks like React do not notice the change.