Search code examples
eclipseselenium-webdrivergmail

Selenium: How do i upload a photo and insert it in the email?


I want to insert a photo in a mail (gmail) by automation in Selenium. I can attach an photo, so that is no problem.

The problem is when i come to this screen and want to change to the Upload tab. I can't find the correct findElement-question.

Image

I have tried these, but dont get it to work:

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

Solution

  • To do that first switch to frame i.e

    WebElement framename=driver.findElement(By.id("amtponuhel03"));
    driver.switchTo().frame(frameElement);
    

    Then pass xpath of upload element to upload

    driver.findElement(By.xpath("//*[@id=':7']/div[.='Upload']"));
    

    this should work