我使用的是eclipse版本:HeliosServiceRelease1,Build : 20100917-0705和selenium 3.141.59,但是当我尝试使用这个sendKeys()函数时,它显示的是错误消息:
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files源代码是:
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");
}
}发布于 2022-03-21 04:16:31
从示例代码中可以看到,您正在尝试传递文件上载(<input type="file">)元素的文件名。
driver.findElement(By.xpath("//*[@id='fileupload']")).sendKeys("filupload");您需要在上面的行中传递要上载的文件的完整路径。
所以代码中的变化会是这样的,
driver.findElement(By.xpath("//*[@id='fileupload']")).sendKeys("C:\\\\Users\\Achint\\Desktop\\Files\\Filename.txt");这个应该适合你。
发布于 2020-05-11 05:38:20
我认为您在文件上传按钮中使用sendkey命令
driver.findElement(By.xpath("//*[@id='fileupload']")).sendKeys("filupload");将文件路径传递给sendkey参数,然后尝试
发布于 2022-02-18 13:02:57
在软件测试公司中,qa工程师提供不同类型的测试服务,如安全测试服务等。
在上面的场景中,当我们使用按钮id = ' fileupload‘上传任何文件时,我们必须将文件路径传递给'SendKeys’函数。
https://sqa.stackexchange.com/questions/43101
复制相似问题