Can you interact with an element without first saving as an object

Good morning,

My question is whether it is possible to interact with an element using the keywords but without having to save as an object first - i.e. define the object in the script/test step. There are many of my tests which are the only interaction with an object and I was thinking in ways how to keep the object library less cluttered.

One way would be to set the xpath/css entirely as a variable in 2 objects (1 each for xpath and css) but thought there might be a better way.

Maybe what I am thinking wouldn’t be good practice so happy for any feedback.


See Creation of Test Object in Memory at Runtime

static TestObject makeTO(String css) {
    TestObject to = new TestObject()
    to.addProperty("css", ConditionType.EQUALS, css)
    return to
1 Like

Hi there, Thanks for the response here - I will give this a go.

Assuming that to do this it is just a case of calling the keyword with the css statement as the parameter? (for context here, I’m not a programmer - definitely something I need to put on my todo list)

For xpath would it be

static TestObject makeTO(String xpath) {
    TestObject to = new TestObject()
    to.addProperty("xpath", ConditionType.EQUALS, xpath)
    return to

Wondering if the keyword could be modified so you pass in 2 params - first is the method (xpath or css) and then second is the statement?

Give it a try. Then you will learn.

Perhaps, you should create 2 methods with unique name:

static TestObject testObjectByXPath(String xpath) { ... }

static TestObject testObjectByCss(String selector) { ... }