How to select dynamic number link using WebDriver for Java

I am trying to fetch a dynamic number link in Webdriver. The problem is this: Xpath and href

depend on the order id, which changes in each order. In this particular case:

XPath = "//*[@id='transSummaryRow_1195908']/td[1]/a"
href ="ftransDetails.aspx?FTID=1195908&OID=904096">1195908"

      

Here is what I tried but it doesn't work.

public static WebElement lnk_TransHistPayId(WebDriver driver){
    element = driver.findElement(By.linkText("ftransDetails.aspx?FTID="+"\\d+"+"&OID"+"="+"\\d+"));
    return element;
}

      

+3


source to share


1 answer


Try the following:



//or this can be done also: By css = By.cssSelector("[id^='transSummaryRow_']/td[1]/a");
By css = By.cssSelector("[href^='ftransDetails.aspx?FTID=']");

public static WebElement lnk_TransHistPayId(WebDriver driver){
    element = driver.findElement(css);
    return element;
}

      

0


source







All Articles