0

In the screen how to navigate to the row which contains the text that needs to be Edited and then click on Edit button.

Scenario: I have a screen where I need to find the row which has the value as "test", then click on the Edit button of that row and then edit the value and remark column in that row and save... I have taken the xpath by position of the value "test" in the screen but this cannot work bz if the user enters a new value and the position of the value "test" changes then it will not click on the edit button . Similarly I have also taken the position of the field - value and remark... Below is the Code:

  1. First

      //*[@id='mainForm:propertiesTable_data']/tr[47]/td[1]/following::a/span[contains(@class,'ui-icon-pencil')] ….
    

    This is the Xpath of the Edit button which has the value "test" which is in the 47th position in the table

  2. I am clicking on the above path with this code -

    PageUtil.clickOnButton(driver, AppXPathsConstants.PropertiesEditIcon);
    
  3. WebElement

    Value = driver.findElement(By.xpath(("(//input[contains(@class,'ui-inputfield') and @role='textbox'])[93]")));--------------> 
    

    This is the xPATH OF THE FIELD VALUE which is in the 93rd position

  4. So I am clicking on the field, moving to the cursor to the left side of the text box by using Home button and then entering the value for the field which is read from the Feature file:

    Value.click();
    Value.sendKeys(Keys.HOME);
    DriverUtil.waitTime(1000);
    PageUtil.clearInputElement(Value);
    PageUtil.inputFieldEntry(driver,AppXPathsConstants.PropertiesValue,formEntryMap.get("Value"));
    

Now since the position of the field test can change when some other text is entered so it is not the right way of taking the Xpath and Editing and adding the text ….can some one please tell me how to go with this.

0

The problem with using Xpath is understandable, but it's not easy to help without the HTML code. I'd recommend using another locator strategy. Is it only the row you want to interact with the one with the value "test"? If yes, in that case, if you're working in a table, you could search for all the rows elements and then select the one with that value. Then you'll be able to interact inside it.

I'll put code in ruby, but I think it will give you an idea about what I mean:

table_element = @browswer.find_element(:tag_name, "table")
rows = table_element.find_elements(:tag_name, "tr")
the_row_you_need = rows.select do |row|
   row.text.include? "test"
end.first

// Then you have the proper row to interact
the_row_you_need

Does this help? Basically, I'm recommending avoiding using XPath as a locator, for the sake of your health. It should be the last option IMO

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.