Forum Discussion

NicolaFilosa_SE's avatar
NicolaFilosa_SE
Contributor
11 months ago
Solved

Using array values in xpath

Hi to everyone. I want to do a for cycle with elements defined by an xpath. The values that the for cycle uses are defined in an array. How can I insert the elements of the array in the xpath?

pageParameterDevice.FindElement("//tr[@id='rowPar2']/td[contains(@class, 'valdev')]").contentText

The value that has to change is 'rowPar2' (from rowPar1 to rowPar737)

Thanks in advance

  • Something like this?

     

    function TestIt()
    {
        var rowPar = [
            "rowPar1",
            "rowPar2",
            "rowPar3",
            "rowPar4",
            "rowPar5"
        ];
        
        for (var i = 0; i < rowPar.length; i++) {
            var str = "//tr[@id='" + rowPar[i] + "']/td[contains(@class, 'valdev')]";
            //pageParameterDevice.FindElement(str).contentText
            Log.Message(str);
        }
    }

    Construct the string, and then pass the str into FindElement()

     

2 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Something like this?

     

    function TestIt()
    {
        var rowPar = [
            "rowPar1",
            "rowPar2",
            "rowPar3",
            "rowPar4",
            "rowPar5"
        ];
        
        for (var i = 0; i < rowPar.length; i++) {
            var str = "//tr[@id='" + rowPar[i] + "']/td[contains(@class, 'valdev')]";
            //pageParameterDevice.FindElement(str).contentText
            Log.Message(str);
        }
    }

    Construct the string, and then pass the str into FindElement()