Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我试图在执行文件上载时执行单击操作,但无法执行_Java_Xpath_File Upload_Selenium Webdriver - Fatal编程技术网

Java 我试图在执行文件上载时执行单击操作,但无法执行

Java 我试图在执行文件上载时执行单击操作,但无法执行,java,xpath,file-upload,selenium-webdriver,Java,Xpath,File Upload,Selenium Webdriver,我正在尝试在执行文件上载时执行单击操作 页面的html代码为 <button class="w85bt fl" onclick="clearDefaultTextCV('copyPaste');truncateTextCv();if(gbi('upUrl').value != 'false' || gbi('copyPaste').value.length>0){gbi('editForm').submit();}" type="button"> <div> <

我正在尝试在执行文件上载时执行单击操作 页面的html代码为

<button class="w85bt fl" onclick="clearDefaultTextCV('copyPaste');truncateTextCv();if(gbi('upUrl').value != 'false' || gbi('copyPaste').value.length>0){gbi('editForm').submit();}" type="button">
<div>
<p><p/>
<b>Save</b>
<em/>
我正在执行上述操作。 但我的代码无法执行单击操作。
它不会引发异常,没有找到这样的元素

我认为您的定位器很好,能够定位元素

现在使用下面的代码点击按钮

WebElement element= driver.findElement(By.cssSelector(".w85bt.fl"));

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
如果仍然无法工作,请检查DOM中是否存在任何帧。 如果没有框架,则检查定位器,可能是定位器有问题


希望它能帮助您:)

您可以使用以下代码:

driver.findElement(By.id("Your_FileUpload_id")).sendKeys("C:\\Your_FilePath");
Thread.sleep(2000);

driver.findElement(By.id(uiMaps.getProperty("UploadOption"))).click();

希望对你有用

它是否打印了
保存按钮
或之前失败?请提供更多HTML代码以尝试使用其他定位器。您是否也尝试过在单击之前提供sleep may Thread.sleep(3000)。单击前的一段时间睡眠将正确模拟。它打印保存按钮,但无法执行单击操作。您可以告诉我uiMaps的作用是什么,因为它显示错误uiMaps无法解决感谢帮助UIMap是一个用于定义、存储和服务应用程序或网站的UI元素的概念。UIMap属性文件包含一组“键-值”对,其中键是UI元素的别名,值是定位器。为了简单起见,您可以使用以下代码:driver.findElement(By.id(“您的上传按钮”);
driver.findElement(By.id("Your_FileUpload_id")).sendKeys("C:\\Your_FilePath");
Thread.sleep(2000);

driver.findElement(By.id(uiMaps.getProperty("UploadOption"))).click();