Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 如何查找xpath或查找标记输入和类型的删除=';图像';含硒_Java_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

Java 如何查找xpath或查找标记输入和类型的删除=';图像';含硒

Java 如何查找xpath或查找标记输入和类型的删除=';图像';含硒,java,selenium,xpath,css-selectors,webdriverwait,Java,Selenium,Xpath,Css Selectors,Webdriverwait,我正在尝试自动化一个我面临问题的web应用程序。问题是我想点击一个按钮,这是导出按钮,它将要求导出到pdf或Excel。在检查时,我可以找到元素,但在运行脚本时,它没有单击按钮。该按钮具有标签输入和类型图像 我尝试过下面这样的不同xpath,也尝试过不点击按钮的绝对xpath driver.findElement(By.xpath("//input[@name='exportReport']")).click(); 及 确保您的元素不在iframe内,如果是这样,您必须首先切换到ifram

我正在尝试自动化一个我面临问题的web应用程序。问题是我想点击一个按钮,这是导出按钮,它将要求导出到pdf或Excel。在检查时,我可以找到元素,但在运行脚本时,它没有单击按钮。该按钮具有标签
输入
和类型
图像

我尝试过下面这样的不同xpath,也尝试过不点击按钮的绝对xpath

driver.findElement(By.xpath("//input[@name='exportReport']")).click();



确保您的元素不在
iframe
内,如果是这样,您必须首先切换到
iframe
,然后执行操作。如果没有,请尝试使用以下代码

WebDriverWait wait = new WebDriverWait (driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.name("exportReport"))).click();

看来你很接近。当您尝试在元素上单击()
而不是在元素上单击EC时,您需要使用
elementtobelickable()
,您可以使用以下任一选项:

  • css选择器

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.birtviewer_clickable[name='exportReport'][src^='birt/images/ExportReport'][alt='Export report']"))).click();
    
  • xpath

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='birtviewer_clickable' and @name='exportReport'][starts-with(@src, 'birt/images/ExportReport') and @alt='Export report']"))).click();
    

您可以尝试使用下面给定的代码段

WebDriverWait wait = new WebDriverWait (driver, 20);

wait.until(ExpectedConditions.visibilityOf( 
driver.findElement(By.xpath("//input[@src='birt/images/ExportReport.gif']")));

driver.findElement(By.xpath("//input[@src='birt/images/ExportReport.gif']")).click();

你的浏览器是什么,它的版本是什么?你是得到
元素点击拦截
还是
无点击例外
?我使用的是Chrome,版本是75.0.3770.142现在我得到的是无点击例外。嗨,当我尝试这个时,它会显示“org.openqa.selenium.Element点击拦截例外:”@sai签出更新的答案并让我知道状态
WebDriverWait wait = new WebDriverWait (driver, 20);

wait.until(ExpectedConditions.visibilityOf( 
driver.findElement(By.xpath("//input[@src='birt/images/ExportReport.gif']")));

driver.findElement(By.xpath("//input[@src='birt/images/ExportReport.gif']")).click();