有人可以幫我在下面?如何點擊一個按鈕使用按鈕的標籤文字
我想點擊一個按鈕誰的文本「繼續掃描」。 在下面的腳本中。而不是硬編碼(簡歷掃描),我怎麼能從屬性文件傳遞值?
driver.findElement(by.xpath("//button[contains(.,'Resume Scanning')]"));
感謝, 卡納安Ç
有人可以幫我在下面?如何點擊一個按鈕使用按鈕的標籤文字
我想點擊一個按鈕誰的文本「繼續掃描」。 在下面的腳本中。而不是硬編碼(簡歷掃描),我怎麼能從屬性文件傳遞值?
driver.findElement(by.xpath("//button[contains(.,'Resume Scanning')]"));
感謝, 卡納安Ç
嘗試如下:
String label = "Resume Scanning";
driver.findElement(By.xpath("//button[contains(.,'" + label + "')]"));
或者使用String.format
:
String string = String.format("//button[contains(.,'%s')]", label);
driver.findElement(By.xpath(string));
參考:
您可以使用下面的Java代碼來讀取屬性文件
FileInputStream in = new FileInputStream("location of properties file");
Properties prop = new Properties();
prop.load(in);
String buttonText=prop.getProperty(propertyName);
driver.findElement(By.xpath(".//button[contains(text(),'"+buttonText+"')]"));
您可以使用屬性文件中讀取文本值。這裏有一個例子:
inputParams.properties
----------------------
buttonLabel=Resume Scanning
使用下面的示例代碼來讀取屬性文件數據:
FileReader reader=new FileReader("inputParams.properties");
Properties p=new Properties();
p.load(reader);
System.out.println(p.getProperty("buttonLabel"));
希望它能幫助。
謝謝Karthik –
非常感謝。它解決了 –
我用這個String label =「Resume Scanning」; driver.findElement(By.xpath(「// button [contains(。,'」+ label +「')]」)); –