Ask a Question

FindChildbyXpath is not able to identify few objects.

tvklovesu
Contributor

FindChildbyXpath is not able to identify few objects.

Hi,

I am trying to get the object and click on it by using the findchildbyxpath method. The page has more than 10 records and when I used this method It identified few of them and others didn't and the TestComplete throws the following error

 
JavaScript runtime error.
TypeError: Cannot read property 'click' of null
 
NameMapping.Sys.browser.pageRavenCore.searchResults_row_Btn = //div[@data-testid="searchResults"]
 
When I search for record that has 'Recipient' then it identified and able to execute the below line
NameMapping.Sys.browser.pageRavenCore.searchResults_row_Btn.FindChildByXPath('/*[contains(text(),"Recipient")]').click()
tvklovesu_0-1664852198218.png

 

When I search for record that has 'name' it is not identified and getting the above error when tried to click on it. But the same xpath identified the object when I tried in chrome console.

NameMapping.Sys.browser.pageRavenCore.searchResults_row_Btn.FindChildByXPath('/*[contains(text(),"name")]').click()
 
tvklovesu_1-1664852270227.png

I am not sure if I am missing anything in the xpath

TIA

2 REPLIES 2
AlexKaras
Community Hero

Hi,

 

Might it be the timing issue?

Does the problem exist if you insert some delay (e.g.  aqUtils.Delay(5000); ) before the call to the problematic line?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

Hi @AlexKaras,, no even adding delay it didn't find the object, but the object is with in viewpoint. If I use FindElements with complete xpath including the parent like below then it works and clicking on the element. Also In some cases the FindChildByXpath is taking long time to identify the element. 

This works
FindElement("//div[@data-testid=\"searchResults\"]//div[@role=\"button\"]//descendant::*[contains(text(),\"name\")]").click()
 
instead of 
NameMapping.Sys.browser.pageRavenCore.searchResults_row_Btn.FindChildByXPath('/*[contains(text(),"name")]').click()
 
Should I use any other method instead of FindChildByXPath
cancel
Showing results for 
Search instead for 
Did you mean: