我想把一個文本檔案的內容發送到網頁的textArea中,我的第一個代碼是把textFile讀成一個String,然后把它發送到textArea中,但問題是,這個方法需要很多時間,特別是如果檔案很大的話
。是否有其他有效的方法來做到這一點?我想過復制檔案,cntrl A cntrl C cntrl V,但怎么做?
uj5u.com熱心網友回復:
屬性檔案:
Data=我想發送的資料
加載屬性檔案:
public static Properties readProperties = new Properties() 。
public static void loadPropertiesFile() {
File propertiesFile = new File(屬性檔案的位置)。
try {
FileInputStream fileInput = new FileInputStream(propertiesFile)。
readProperties.load(fileInput)。
} catch (Exception e) {
System.out.println("加載屬性檔案時出錯" e.getMessage())。
}
}
讀取屬性檔案并獲得資料:
String inputData = readProperties。 getProperty("Data").trim()。
System.out.println(inputData)。
發送資料:
driver.findElement(By.xpath("text area").sendKeys("inputData")。
uj5u.com熱心網友回復:
我想出了一個快速的解決方案來復制文本檔案的內容,不管檔案的大小。這個想法是在WebDriver中獲取文本檔案,然后使用Selenium復制頁面的內容,如下:
driver.get("file://" "我的文本檔案的本地路徑") 。
String content = driver.findElement(By.xpath("/html/body/pre") ).getText()。
這個方法很快速,讀取文本檔案內容的時間低于一秒
。轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/327094.html
標籤:
上一篇:Selenium錯誤。訊息:無效的引數:'url'必須是一個字串
下一篇:在Selenium中關閉標簽會使current_window_handle=NoneType,即使有另一個標簽打開也是如此。
