如何使用WebDriver for Java选择动态数字链接

时间:2015-06-01 20:15:45

标签: java selenium xpath

我试图在 Webdriver 中选择动态数字链接。问题是这样的: xpath href都依赖于每个订单更改的订单ID。在这种特殊情况下:

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

这是我尝试过的,但它不起作用。

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

1 个答案:

答案 0 :(得分:0)

试试这个:

//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;
}