new message window elements are not recognized

Well I am trying to write a selenium script to perform below set of actions

1. Open Gmail
2. Click on Compose
3.Switch to new message window
4. Enter To, Subject Body details
5. Click on send

I am not able to identify the elements of new message window, so I used concept of switchTo but even though the elements are not being identified. let me know, If I need to use any other method apart from Switch To.

Please guide me here

package may6th;

import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Googleex {

public static void main(String[] args) {

//System.setProperty(“webdriver.chrome.driver”, “C:\\Selenium\\chromedriver_win32\\chromedriver.exe”);
FirefoxDriver driver = new FirefoxDriver();

driver.manage().window().maximize();

driver.get(“https://www.google.com/?gws_rd=ssl”);

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.findElement(By.xpath(“.//*[@id=’gbw’]/div/div/div[1]/div[2]/a”)).click();

driver.findElement(By.xpath(“.//*[@id=’gmail-sign-in’]”)).click();

driver.findElement(By.id(“Email”)).sendKeys(“”);
driver.findElement(By.id(“Passwd”)).sendKeys(“”);
driver.findElement(By.xpath(“.//*[@id=’signIn’]”)).click();

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“.//*[@id=’:ed’]/div/div”)));

String parent_window= driver.getWindowHandle();

System.out.println(parent_window);

WebElement ele = driver.findElement(By.xpath(“.//*[@id=’:ed’]/div/div”));
ele.click();

Set li = driver.getWindowHandles();
System.out.println(li);

int totalsize = li.size();

System.out.println(totalsize);

Iterator i1 = li.iterator();

while (i1.hasNext())

{

String chil_window =i1.next();

if(!chil_window.equalsIgnoreCase(parent_window))

{

driver.switchTo().window(chil_window);
driver.findElement(By.xpath(“.//*[@id=’:jk’]”)).sendKeys(“premkh.9@gmail.com”);
driver.findElement(By.xpath(“.//*[@id=’:j5′]”)).sendKeys(“hello”);

driver.findElement(By.xpath(“.//*[@id=’:qx’]’]”)).sendKeys(“Hello, How are you doing”);
driver.findElement(By.xpath(“.//*[@id=’:pl’]”)).sendKeys(Keys.RETURN);

}

}

//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“.//*[@id=’:jk’]”)));

//driver.switchTo().window(parent_window);

driver.findElement(By.xpath(“.//*[@id=’gb_71′]”)).sendKeys(Keys.RETURN);

}

}

Add Comment
  • 1 Answer(s)

    Hi,

    Even I faced some similar issues while automating the compose mail part from the gmail but fortunately I happened to trouble shoot the problem.Hope it works for you too.here it is what i did, I just changed the the attributes in the locators in the XPATH. Moreover to be precise ,I used “class” attribute instead of the “id’s” ┬áin the XPATH.Hope it helps you in this.

    Cheers,,

    Default Answered on May 7, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.