首页 > 解决方案 > 如何在 selenium java 中将文本文件发送到 textarea

问题描述

我想将文本文件的内容发送到网页的 textArea,我的第一个代码是将 textFile 读入字符串,然后将其发送到 textArea 但问题是这种方法需要很多时间,特别是如果文件很大

还有另一种有效的方法吗?我想复制文件 cntrl+A cntrl+C cntrl+V 但是怎么做呢?另一个想法是将文本文件拖放到文本区域中,但这对我不起作用

标签: javaseleniumselenium-webdriverwebdriver

解决方案


属性文件

Data=The data which I want to send

加载属性文件

public static Properties readProperties = new Properties();
public static void loadPropertiesFile() {
    File propertiesFile = new File(location of properties file);
    try {
        FileInputStream fileInput = new FileInputStream(propertiesFile);
        readProperties.load(fileInput);
    } catch (Exception e) {
        System.out.println("Error in loading the Properties file" + e.getMessage());
    }
}

读取属性文件并获取数据

String inputData = readProperties.getProperty("Data").trim();
System.out.println(inputData);

发送数据

driver.findElement(By.xpath("element of text area")).sendKeys("inputData");

推荐阅读