在xpath中放置变量

时间:2016-06-16 08:47:13

标签: java selenium selenium-webdriver

我需要在xpath中传递一个变量,其中此xpath将被标识为变量更改。我想要的代码如下:

String TicketData = TicketName; //provided from spreadsheet
   //Insert variable into xpath
  driver.findElement(By.xpath("//h3[contains(text(), 'TicketName')]")).getText();

2 个答案:

答案 0 :(得分:2)

你可以这样做:

String TicketData = TicketName; //provided from spreadsheet
//Insert variable into xpath
driver.findElement(By.xpath("//h3[contains(text(), "+TicketName+")]")).getText();

答案 1 :(得分:0)

driver.findElement(By.xpath("//h3[contains(text(), " + TicketData + "')]")).getText();

By.xpath(String.format("//h3[contains(text(), %s)]", TicketData));