Java 如何查找xpath或查找标记输入和类型的删除=';图像';含硒
我正在尝试自动化一个我面临问题的web应用程序。问题是我想点击一个按钮,这是导出按钮,它将要求导出到pdf或Excel。在检查时,我可以找到元素,但在运行脚本时,它没有单击按钮。该按钮具有标签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
输入
和类型图像
我尝试过下面这样的不同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();