UnsupportedOperationException in TestBench

When I pass the WebElement from getDriver().findElement() into the Selenium’s Select class constructor, I get the follow exception…

java.lang.UnsupportedOperationException: getDomAttribute
    at org.openqa.selenium.WebElement.getDomAttribute(WebElement.java:131)
    at org.openqa.selenium.support.ui.Select.<init>(Select.java:54)

this is the code that lead to that exception.

import org.openqa.selenium.support.ui.Select;

    Select select = new Select(getDriver().findElement(By.id("shippingAdministrativeArea")));

This started when I upgraded to v23 from v21. From doing a Google search, it is mentioned that this error can occur if Selenium v4 dependency mismatch. I checked the maven dependency tree and all Selenium artifacts are 4.1.4.

[INFO] |  |  |  +- org.seleniumhq.selenium:selenium-api:jar:4.1.4:test

Any idea what the issue could be?

The internal structure of the webcomponents changed quite drastically from 21->23 to comply with accessibility, which could cause issues with selenium (and selenium is kinda outdated)

Ah. So what should we do about it?

Use Selenium 4.5.3

Cool, I’ll try that. The thing is that I didn’t pick it. Its what TestBench chose. But I can overwrite it to use this newer version.

You can always go to https://start.vaadin.com and create a new project with the latest Vaadin version and check the pom.xml for versions of the dependencies

That’s how I upgrade projects

Wait… you use Testbench and are using a Selenium import from “Select”? Do you have a native select element?

Yes and yes.

Thats what I did. I didn’t select the version of TestBench. It came from the vaadin-bom. Currently using version 23.2.6 of the vaadin-bom.

That version is probably dictated by spring boot (which is behind the version Testbench uses)

Indeed the version must be overridden because Spring Boot uses a very old version

Tried it out, but it didn’t work.

First I noticed that Selenium 4.1.4 is coming from TestBench 8.1.1.

[INFO] +- com.vaadin:vaadin-testbench-core:jar:8.1.1:test
[INFO] |  +- org.seleniumhq.selenium:selenium-remote-driver:jar:4.1.4:test

If I upgrade to any version above that, I get a NoClassDefFoundError exception.

FYI, the native select that I am trying to test is from Stripe’s checkout page. Its the one for selecting the billing address’ state.

I think I’m going to try to wrap the WebElement from Vaadin TestBench in a proxy class that will convert getDomAttribute to getAttribute.

ok the proxy worked. Here it is in case you guys come across this again.

    var webElement = getDriver().findElement(By.id("shippingAdministrativeArea"));
    var spyWebElement = Mockito.spy(webElement);
    doAnswer(invocation -> webElement.getAttribute(invocation.getArgument(0)))
    Select select = new Select(spyWebElement);