首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium - sendKeys()函数不适用于文件上载。

Selenium - sendKeys()函数不适用于文件上载。
EN

Stack Exchange QA用户
提问于 2020-03-28 07:44:00
回答 4查看 2K关注 0票数 2

我使用的是eclipse版本:HeliosServiceRelease1,Build : 20100917-0705和selenium 3.141.59,但是当我尝试使用这个sendKeys()函数时,它显示的是错误消息:

代码语言:javascript
复制
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files

源代码是:

代码语言:javascript
复制
package AutomationFramework;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
//import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.Alert;
//import org.openqa.selenium.WebElement;


public class HandleFileupload {

    public static WebDriver driver = null;
    
    public static void main(String[] args) 
    {
    
        System.getProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get("https://html.com/input-type-file/");
        driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS );
        driver.manage().window().maximize();
        driver.findElement(By.xpath("//*[@id='fileupload']")).sendKeys("filupload");
                
    }

}
EN

回答 4

Stack Exchange QA用户

发布于 2022-03-21 04:16:31

从示例代码中可以看到,您正在尝试传递文件上载(<input type="file">)元素的文件名。

代码语言:javascript
复制
driver.findElement(By.xpath("//*[@id='fileupload']")).sendKeys("filupload");

您需要在上面的行中传递要上载的文件的完整路径。

所以代码中的变化会是这样的,

代码语言:javascript
复制
driver.findElement(By.xpath("//*[@id='fileupload']")).sendKeys("C:\\\\Users\\Achint\\Desktop\\Files\\Filename.txt");

这个应该适合你。

票数 1
EN

Stack Exchange QA用户

发布于 2020-05-11 05:38:20

我认为您在文件上传按钮中使用sendkey命令

代码语言:javascript
复制
driver.findElement(By.xpath("//*[@id='fileupload']")).sendKeys("filupload");

将文件路径传递给sendkey参数,然后尝试

票数 0
EN

Stack Exchange QA用户

发布于 2022-02-18 13:02:57

在软件测试公司中,qa工程师提供不同类型的测试服务,如安全测试服务等。

在上面的场景中,当我们使用按钮id = ' fileupload‘上传任何文件时,我们必须将文件路径传递给'SendKeys’函数。

票数 0
EN
页面原文内容由Stack Exchange QA提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://sqa.stackexchange.com/questions/43101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档