How to find xpath or to findelement of tag input and type='image' in selenium

I’m trying to automate a web application in which I’m facing a problem. The problem is I want to click a button which is Export button which will ask to export in to pdf or Excel. While inspecting I can find the element but while running the script it is not clicking the button. The button is having tag input and type image.

I’ve tried with different xpaths like below and also I’ve tried absolute xpath which is not clicking on the button.

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

and

WebDriverWait wait = new WebDriverWait (driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@name='exportReport']")));
driver.findElement(By.xpath("//input[@name='exportReport']")).click();

3
Leave a Reply

avatar
3 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Seems you were close. As you are trying to click() on the element instead of EC as visibilityOfElementLocated() you need to use elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    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();
    
Jason
Guest

Make sure your element is not within an iframe if so, you have to first switch into the iframe and then perform the action. If not, give a try with the below code.

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

Jason
Guest

You can try using the below given code snippet

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();