//div[@id='picombobox-2144-trigger-picker'] 2144 is keep on changing. How to handle this xpath and put it in the code

String dynamicID=‘picombobox-2144-trigger-picker’
String xpath=’//div[@id="’ + dynamicID + ‘"]’
TestObject to= new TestObject(“objectName”)
to.addProperty(“xpath” , ConditionType.EQUALS,xpath)
WebUI.enhancedClick(to)

//div[contains(@id,'picombobox-') and contains(@id,'-trigger-picker')]

Just ignore the moving part.

2 Likes

Should I ignore rest of the code and directly add xpath as like this //div[contains(@id,‘picombobox-’) and contains(@id,’-trigger-picker’)]


It says the test case passed, but the click didn’t happen on the browser.

1 Like

Do you know how to use DevTools to check if your xpath is unique?

@mounica.ravi

You have the following code now:

String dynamicID='contains(@id,"picombobox-") and contains(@id,"-trigger-picker")'
String xpath='//div[@id=]' + dynamicID + ']'

TestObject to = new TestObject("objectName")
to.addProperty("xpath", ConditionType.EQUALS, xpath)
WebUI.delay(5)
WebUI.enhancedClick(to)

Here you have at least 2 problems.

(1) your ‘xpath’ is wrong.

please change you code and try running it:

String dynamicID='contains(@id,"picombobox-") and contains(@id,"-trigger-picker")'
String xpath='//div[@id=' + dynamicID + ']'
println "xpath is " + xpath

this will give you a message in the Console

xpath is //div[@id=contains(@id,"picombobox-") and contains(@id,"-trigger-picker")

The expression is NOT a valid XPath expression. Can you see it?

(2) You should verify if the element is present before clicking it.

You should write:

WebUI.verifyElementPresent(to, 5)
WebUI.enhancedClick(to)

This will give you a Failure when the HTML element pointed by your XPath expression is not present.

The enhancedClick(to) may not throw error when the give Test Object (to) points nothing, I am not sure. You should not expect enhancedClick() to verify the presence of the target HTML element. You should rather explicitly call verifyElementPresent() to verify the presence of the target HTML element.

It says element is not present.

So what do you want others to do? You should investigate it for yourself. Perhaps, as @grylion54 mentioned, the DevTools of Chrome browser may help.

1 Like

When I use dev tools it says element presents but when I run the test case element is not present.

When you use DevTools, you manually operate a Browser. It is slowly enough. The target HTML element would be already displayed in the browser window before you let DevTools to look up the element of your interest.

On the other hand, when your script runs, the script runs far faster. It is likely that an HTML element is absent = is not yet displayed in the browser window.

You should be aware of the difference between these 2 situation — timing issue.

Let me look back your test script.

...
WebUI.enhancedClick(findTestObject("Object Repository/Project/Activity"))    // (1)
...       // (2)
WebUI.enhancedClick(to)    // (3)

When the (1) statement runs, I suppose, the browser will navigate a new URL; a new HTML page is loaded. It may take several seconds. Loading a new page may take 1 second? 3 seconds? … could be longer.

However, at (2), your code doesn’t explicitly wait for the page to load. In just a few milliseconds after the (1), your code reaches to the statement (3) and try to find an HTML element on the new page, which is most probably not yet loaded. So your script will find “the element is not present”.

I would repeat this: your script should call veryfyElementPresent(TestObject, timeout) before the 2nd enhancedClick().

1 Like

Possibly you typed something correct in the dev tools, but you typed something wrong in your test case. Nobody, other than you, can see what you typed.