Forum Discussion

apurvak's avatar
apurvak
Occasional Contributor
7 years ago

Incrementing Xpath value.

Hi,

 

I am trying to insert values in a table row using Xpath. For the first time values are inserted correctly but when I am trying to insert values for second time it is inserted in same row.

 

page.FindChildByXpath("//div[1]/div[2]/div[2]/div/div/div/div[2]/div[1]/div/table/tbody/tr/td/table/tbody/tr[5]/td/div/div[3]/table/tbody[1]/tr[8]/td[1]/div/span/input",true);

 

I need to increment the highlighted value in Xpath.

 

I tried to increment using for loop but it is giving error as "Cannot read property 'FindChildByXpath' of undefined"

 

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I'm not sure I understand what you are trying to do. While I don't use the FindChildByXpath method myself, as I understand it, it's purpose is not to alter data in a table but to find an object on a page using the XPath.  So, based upon the code you posted, I'm not sure how you're actually doing what you are trying to do.

     

    Just as a guess... if you want to find a bunch of objects using XPath and increment specific portions of your xpath based upon a for loop, I'd write it like this:

     

    for (var i=0; i < maxValue; i++){
    myObject = page.FindChildByXpath("//div[1]/div[2]/div[2]/div/div/div/div[2]/div[1]/div/table/tbody/tr/td/table/tbody/tr[5]/td/div/div[3]/table/tbody[1]/tr[ " + i + "]/td[1]/div/span/input",true);
    //execute whatever you need to against myObject
    }