Ask a Question

object not found when using a variable in keyword test On screen action

SOLVED
tvklovesu
Frequent Contributor

object not found when using a variable in keyword test On screen action

Hi,

I was trying to find an element and click on it using the keyword test and on screen action. But the object is not found error is displayed.

The variable I am passing here is "ProjectSuite.Variables.i". But the same thing when I use in script mode it is working fine. Not sure what's the problem here.

 

Aliases.RavenDarttsPge.findElement("(//div[contains(@class,'MuiGrid-root MuiGrid-item') and contains(.,'Available columns')]//div[@role='list']//div[contains(@id,'transfer-list-all-item')])[" + ProjectSuite.Variables.i + "]")

 

Keyword test

tvklovesu_0-1692116775674.png

error message

The "Aliases.RavenDarttsPge.findElement("(//div[contains(@class,'MuiGrid-root MuiGrid-item') and contains(.,'Available columns')]//div[@role='list']//div[contains(@id,'transfer-list-all-item')])[" + ProjectSuite.Variables.i + "]")" object was not found
 
The issue here is that variable is not replaced with the value when I execute. This is working fine if I use the variable for any class name, ID or any other attribute.

 

2 REPLIES 2
rraghvani
Champion Level 3

You can not use variable substitution in XPath query. However, you can do something like this, construct your string first

var xpath = aqString.Format("//div[@role='list']//div[contains(@id,'%s')", ProjectSuite.Variables.i);

where %s will be replaced. Then pass it to,

Aliases.RavenDarttsPge.findElement(xpath)
tvklovesu
Frequent Contributor

Thanks for your tip,

I did not use the aq string, but used the code expression while assigning the variable value as follows and now it works.

 

tvklovesu_0-1692119131599.pngtvklovesu_1-1692119193434.png

 

cancel
Showing results for 
Search instead for 
Did you mean: