2016-06-16 78 views
-1

我需要在xpath中傳遞一個變量,其中這個xpath將被識別爲變量的變化。我打算代碼如下:在xpath中放置一個變量

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

如果virusrocks回答是正確的,請把它標記爲接受這樣他得到了他所做的工作的榮譽。 – JeffC

回答

2

你可以這樣說:

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

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

這是正確的答案:driver.findElement(By.xpath(「// h3 [contains(。,'」+ TicketName +「')]」))。getText(); – AzMar