我需要在xpath中传递一个变量,其中此xpath将被标识为变量更改。我想要的代码如下:
String TicketData = TicketName; //provided from spreadsheet
//Insert variable into xpath
driver.findElement(By.xpath("//h3[contains(text(), 'TicketName')]")).getText();
答案 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));