My Scenario:

  1. I need to create a Demand. After creation the Id of the Demand will be autogenerated
  2. I need to fetch that id and use it in another screen

Question: While I created the Demand and try to fetch the Id there will be multiple users who will create Demands at the same time and there will be multiple ids which will get generated. So I need to get only the of the Demand I created. How do I handle this?

So far I have tried to fetch the latest id by using HashMap and it should not be done that way.

The code I have used to fetch the id is:

public static HashMap<String, String> createdValue; public static void FetchID(WebDriver driver) throws InterruptedException {

    createdValue = new HashMap<String, String>();

    List<WebElement> tableValues = driver.findElements(By.xpath("//table//tr//td[contains(@class,'mat-column-demandId')]//span"));

    int tableValueSize = tableValues.size();

    WebElement latestId = driver.findElement(By.xpath("(//table//tr//td[contains(@class,'mat-column-demandId')]//span)["+tableValueSize +"]"));

    createdValue.put("latestDataId", latestId.getText()); 

    System.out.println(createdValue.put("latestDataId", latestId.getText()));

    inputEntry(driver, .SearchInputXpath , createdValue.put("latestDataId", latestId.getText()));



The above code will only fetch the latest id but as specified I need to get the Id of the Demand I created.

Any leads on this?

  • Does the demand you create have any other data you can use to identify it? For instance, is there a description you can make unique?
    – Kate Paulk
    Sep 14 at 11:29
  • @KatePaulk -Its only the Id which is unique as the rest will be the same
    – jay m
    Sep 14 at 11:53
  • In that case, getting the latest ID is the best you can do.
    – Kate Paulk
    Sep 15 at 13:24
  • @ Kate Paulk - yes that's right but the question is how to do it
    – jay m
    Sep 15 at 13:42

Your Answer

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

Browse other questions tagged or ask your own question.