Forum Discussion

william_roe's avatar
william_roe
Super Contributor
9 years ago
Solved

More Help with XPath

I thought I had figured out this XPath thing but appararently not.

 

I'm trying to find the all div tags with the class "dxbButtonSys". A snippet of the browser inspect window is below.

 

I'm using the following code but can seem to find it. I've inspected the innerHTML to confirm the 'section' is contains the div.

 

What am I doing wrong???

 

    section = Sys.Browser().Page("*").Panel("primaryWrapper").Section("primaryContent").Nav("contentNav").Panel("mainNav").Panel("cplMainMenu").Panel("pcNavigation").Panel("pcNavigation_CC").Panel("pcNavigation_C3").Panel(0).Article(0);
    arr = section.EvaluateXPath("//div[@class='dxbButtonSys']", true);
    
    if(arr != null)
      return false;

 

xpath div.JPG

  • HKosova's avatar
    HKosova
    9 years ago

    william_roe wrote:

    Although all the elements of 'arr' are 'undefined' ....


    In JScript, you need to convert arrays returned by EvaluateXPath/QuerySelectorAll/FindAllChildren/etc methods to the JScript array format:

     

    arr = section.EvaluateXPath("//div[@class='dxbButtonSys']", true);
    if (arr != null) {
      arr = (new VBArray(arr)).toArray();
      Log.Message(arr.length);
    }
    else {
    Log.Message("Not found");
    }

3 Replies

  • william_roe's avatar
    william_roe
    Super Contributor

    Although all the elements of 'arr' are 'undefined' this works for my purposes of determining if any div exists with class 'dxbButtonSys'.

     

    Anyone see a problem with this?

     

     

        section = Sys.Browser().Page("*").Panel("primaryWrapper").Section("primaryContent").Nav("contentNav").Panel("mainNav").Panel("cplMainMenu").Panel("pcNavigation").Panel("pcNavigation_CC").Panel("pcNavigation_C3").Panel(0).Article(0);
        arr = section.EvaluateXPath("//div[contains(@class, 'dxbButtonSys')]");
        if(arr != null)
          return false;
    • Amstel_Bytes's avatar
      Amstel_Bytes
      Occasional Visitor

      I recently had to find labels on a page that is visible only and made the following function.

       

      Example usage:  VerifyVisibleLabel("Surname")

       

       

      function VerifyVisibleLabel(labelName) {
      	try {
      		var page = Sys.Browser("*").Page("*");
      		page.Wait();
      
      		var labels = page.FindAllChildren("nodeName", "LABEL", 50);
      		var labelFound = false;
      
      		labels = (new VBArray(labels)).toArray();
      
      		if (labels.length > 0) {
      			for (i = 0; i < labels.length; i++) {
      				if (labels[i].contentText == labelName && labels[i].Visible == true) {
      					Log.Message("Label found - FullName: " + labels[i].contentText);
      					labelFound = true;
      				}
      			}
      		}
      		if (labelFound == false) {
      			GenError("Label not found: " + labelName)
      		}
      	} catch (exception) {
      		GenError("custom error message here...")
      		return false
      	}
      }

       

    • HKosova's avatar
      HKosova
      SmartBear Alumni (Retired)

      william_roe wrote:

      Although all the elements of 'arr' are 'undefined' ....


      In JScript, you need to convert arrays returned by EvaluateXPath/QuerySelectorAll/FindAllChildren/etc methods to the JScript array format:

       

      arr = section.EvaluateXPath("//div[@class='dxbButtonSys']", true);
      if (arr != null) {
        arr = (new VBArray(arr)).toArray();
        Log.Message(arr.length);
      }
      else {
      Log.Message("Not found");
      }