WebElement as TestObject

I have a WebElement in one script that I need to convert to a TestObject - what’s the best way to do this? Thanks!

Unfortunately, there’s no simple way to do this (that I know of). It’s easy to convert a TestObject to a WebElement, but not the other way around :frowning:

The reason is that once a WebElement is created, there’s no way to ask it how it was created (in other words, ask it for the locator used). TestObjects on the other hand are fundamentally just containers for locators (meaning it’s easy to ask it for a locator value) that the WebUI methods then use to create WebElements from in the background.

The best suggestion I can recommend is this one:

but it’s definitely a hack. It would be nice if there was a native Selenium way of doing this, but I have doubts that there ever will be.

Of course! :crazy_face: I made a change so I wouldn’t have to struggle with that one further. Thanks!

WebUI.convertWebElementToTestObject()

2 Likes