我不明白为什么我得到这个错误:Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument
表示点击动作
package day18;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
public class UploadFileOrange {
public static void main(String[] args) throws InterruptedException, FindFailed {
System.setProperty("webdriver.chrome.driver","C://Drivers//chromedriver_win32/chromedriver.exe" );
WebDriver driver = new ChromeDriver();
driver.get("https://opensource-demo.orangehrmlive.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id="txtUsername"]")).sendKeys("Admin");
driver.findElement(By.xpath("//*[@id="txtPassword"]")).sendKeys("admin123");
driver.findElement(By.xpath("//*[@id="btnLogin"]")).click();
Thread.sleep(3000);
WebElement PIM = driver.findElement(By.xpath("//*[@id="menu_pim_viewPimModule"]"));
WebElement AddEmp = driver.findElement(By.xpath("//*[@id="menu_pim_addEmployee"]"));
Actions act = new Actions(driver);
act.moveToElement(PIM).moveToElement(AddEmp).click().build().perform();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@id="firstName"]")).sendKeys("Fruit");
driver.findElement(By.xpath("//*[@id="lastName"]")).sendKeys("Fruit");
Thread.sleep(3000);
**driver.findElement(By.name("photofile")).click();** //IMAGE UPLOAD BUTTON
Thread.sleep(3000);
String ImageFilePath = "C:\Users\lu.ungaro\Desktop\Corso Automation - Selenium\18";
String InputFilePath = "C:\Users\lu.ungaro\Desktop\Corso Automation - Selenium\18\ClassExamples\ClassExamples\FileUpload using Sikuli\Fruites\inputfiles";
Screen s = new Screen();
Pattern fileInputTextBox = new Pattern(ImageFilePath + "box.PNG");
Pattern openButton = new Pattern(ImageFilePath + "apri.PNG");
Thread.sleep(3000);
s.wait(fileInputTextBox, 20);
s.type(fileInputTextBox,InputFilePath+"apple.jpg");
s.click(openButton);
}
}
当我运行这段代码时,我得到了这个异常:
Starting ChromeDriver 88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784}) on port 10403
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
gen 29, 2021 5:58:30 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument
(Session info: chrome=88.0.4324.104)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'HEA23009', ip: '192.168.215.232', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '14.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 88.0.4324.104, chrome: {chromedriverVersion: 88.0.4324.96 (68dba2d8a0b14..., userDataDir: C:UsersLU5787~1.UNGAppDa...}, goog:chromeOptions: {debuggerAddress: localhost:62977}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 33ff537b7ce0eb56b57c2ce2f9025633
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at day18.UploadFileOrange.main(UploadFileOrange.java:44)
我正在尝试使用SIKULI在测试网站上传图像。我使用WebDriver访问网站,并执行一系列操作以进入上传图像页面。
第一个点击动作(登录)工作,但代码停止运行时,我试图执行点击动作对图像上传按钮。我尝试了不同的定位器,但我总是得到这个
我也下载了最新版本的ChromeDriver。
但我不知道是什么问题
谢谢你的帮助
请尝试使用JavaScript执行点击选项。遇到同样的错误,用下面的代码
解决WebElement element = driver.findElement(By.id("photofile"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);