Ask a Question

Click on Span Object not working occasionally

SOLVED
cadeo
New Contributor

Click on Span Object not working occasionally

I have the following menus in my application 

cadeo_0-1665569370330.png

When I click on 'Self Service Tool' menu or hover over it, the following submenus displays

cadeo_1-1665569535296.png

Here is my code to click on the 'Self Service Tool' submenu.

var Wait = require("Wait");
var browser = Sys.Browser();
var page = browser.Page("*");
Wait.findObject("//li/a/span[contains(text(),'Self Service Tool')]").Click();
Delay(1000);
Wait.findObject("//li/a/span[contains(text(),'Prior Authorization Work Queue')]").Click();
Delay(3000);

----------------------------------

function findObject(selector)
{
var browser = Sys.Browser();
var page = browser.Page("*");
var obj = page.WaitElement(selector,1000);
while (obj.Exists == false){
obj = page.WaitElement(selector,1000);
}
return obj;
}

 The click on the 'Self Service Tool' object occasionally not working. The HTML attributes of the object are shown below.

 

cadeo_3-1665570018913.png

 

In the logs, I can see Click is performed but the sub-menu list is not populating

cadeo_0-1665571228568.png

cadeo_0-1665571773731.png

 

5 REPLIES 5
tvklovesu
Frequent Contributor

Hi @cadeo,

Instead of you use Span try using the <a> tag like below. By doing that it takes the full area of the object.

 

wait.findObject("//li/a[contains(text(),'Self Service Tool')]").Click();

Kitt
Regular Contributor

Agree with @tvklovesu, you can try removing span from your xpath OR instead of using //li/a[contains(text(),'Self Service Tool')] you can use "." to expand your search //li/a[contains(.,'Self Service Tool')]. I also would highly recommend using a browser extension like ChroPath (or similar) to help you find and validate your xpath objects. TestComplete doesn't always use the best mapping references, so a secondary tool can help ease the burden of relying on the Object Spy tool or weeding through the Object Browser.

[[ kITt: keep IT testing ]]

@tvklovesu  using the <a> tag is not working

cadeo
New Contributor

@Kitt Thanks will check & go for the same

tvklovesu
Frequent Contributor

@cadeo, just realized there is an extra space at the beginning and end of the text. thats why its not able to find the object. use the normalize-space method in the xpath.

ps: Do not copy and paste the below syntax as sometimes the quotes might be replaced with special chars and will not work in code. Please type manually in the code.

//li/a[normalize-space(.) ='Self Service Tool']

cancel
Showing results for 
Search instead for 
Did you mean: