Step failing in terminal

Hello There,

I am trying to run a test on CLI but it is failing there when the same tests is passing in Web.
The test is failing when clicking on “Rechercher”. I have to click there and set a text for it to search for the word i input there.

My xpath is:

I have used focus, waitforElementPresent, delay() but it is showing me error:

I even tried with JS but still it is still be stepfailed in terminal.
I have run out of ideas.
The html is below:
<input _ngcontent-axy-c92="" matinput="" type="search" name="filter" class="mat-input-element mat-form-field-autofill-control ng-tns-c61-0 ng-pristine ng-valid cdk-text-field-autofill-monitored ng-touched" placeholder="Rechercher" id="mat-input-0" data-placeholder="Rechercher" aria-invalid="false" aria-required="false">

Can someone please help me on this. Before clicking on “Rechercher” there is a button, it was able to click it successfully but fails when clicking on “Rechercher”.

I think either it is not able to reach on this small page of the page, but before that the button was on this same size page, it should have failed here as well.
Also is there a possibility that an xpath can be incorrect when it is working correctly on web but not in terminal?

The window size also is set.

Thank you

@anuradha It is a small thing, but with id you can change the format of XPath to:


This style only works for id.

I would still go for waitForElementClickable beforehand to ensure the element is there.

Hello @grylion54, this is not working. Its still cannot find the xpath though the same is working correctly on web.

Now i think in terminal it is not able to see the white place where the search is being done.

Anything else i can try?

Thank you

@anuradha If you copied and pasted the XPath I had above, you have to change the smart quotes–have a curve or curl to them–to straight quotes. Just retype the quotes in KS.

Maybe you can investigate switchToWindowIndex(1) or switchToWindowTitle(‘Choisissez votre etablissment’) before interacting with the white place. You will have to retype the title in your French character set so the text matches.


How about inserting a statement to wait for the target HTML element before moving focus on it?This is just to ensure the target element has been loaded.

TestObject tObj = findTestObject("yourTestObjectId")
WebUI.verifyElementPresent(tObj, 10)    # ADD this; will timeout after 10 seconds 

Hello @kazurayam,

I tried but still it is not able to find the element.

Hello @grylion54, I did rewrite the xpath and switchToWindowTitle is not working here as “Choississez votre etablissement” is not the window title.

I am still having a hard time understanding why its passing in UI and not in terminal.
I tried maximising the window for it to get the element though i have already added this step when i navigate to the url. It worked on first try then failed again.


@anuradha I have had a situation in which the test script worked the first time and started failing afterwards. The cause was to do with a failure in the connection to another application that gave the first application permission/information. Do you have something similar? Maybe a Linker app?

@grylion54 but if this was the case should not it have failed in web also with my script?



You shared the log after verifyElementPresent(tObj,10) only. Could you share the whole log including steps before verifyElementPresent(tObj,10)?

Hello @kazurayam i figured out the cause of the issue. I have this button in in my step which leads to the page where the other clicks has to be done.
What is happening is that sometime the button is being clicked and sometimes not. but most of the time it is not triggering the click.

This is the DOM:

> <a class="btn btn-default btn-sm green create-account-btn" href="/comptes/sources"><i class="fa fa-plus"></i>Button </a>

This is the button:

I used this xpath:
//*[@class=‘btn btn-default btn-sm green create-account-btn’]

And this is happening only on terminal :expressionless:
How can i force the button to be clicked everytime it sees the button?


Also i noticed that all this time when the button was not being clicked i did not get the error in the script in the place where i called the clicked action.
I added WebUI.screenshot in everystep then i got the cause. It should have failed this step in the log if i am not wrong

Then you should try clicking the button using JavaScript. See the following.

I suppose that you expect to see this:

<a class="btn btn-default btn-sm green create-account-btn"

But if your web page is JavaScript-heavy, this node could possibly be

<a class="create-account-btn btn btn-default btn-sm green "

or at another chance

<a class=" green create-account-btn btn btn-default btn-sm"

Please find that in the above 3 instances the order of CSS class names in @class attribute differs. But those are equivalent in terms of CSS. This variation is completely valid. It is up to how JavaScript in the page behaves occasionally.

If the node was generated by JavaScript as <a class=" green create-account-btn btn btn-default btn-sm" , then your XPath

will miss the <a> node on the page.

How to overcome this difficulty of probability? You shouldn’t use equal operator (=) like [@class='xxx xxx '] to test the @class attribute. You should rather use contains(@class, 'xxx') function.

I would rewrite the XPath as follows:

//a[contains(@class,'btn') and contains(@class, 'btn-default') and  contains(@class,'btn-sm') and contains(@class, 'green') and contains('create-account-btn’)]

Or, with the same meaning, the following might be better readable:

//a[contains(@class,'btn')][contains(@class, 'btn-default')][contains(@class,'btn-sm')][contains(@class, 'green')][contains('create-account-btn’)]

In case that there are multiple <a> elements with similar @class in the page, you can write it for uniqueness: