1
  1. Step-1. Click the link from the parent window.The new window gets opened. Say it as a child window.
  2. Step-2. In child window, not able to enter data in the field using selenium webDriver.

code:

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
String parentWindowHandle = driver.getWindowHandle();
driver.findElement(By.xpath("//*[@id='topButtonRow']/input[5]")).click();
Thread.sleep(5000);
Set<String> windowHandles = driver.getWindowHandles();
System.out.println(windowHandles.size());
Iterator<String> it = windowHandles.iterator();
String wHandle = null;
while (it.hasNext()) {
    wHandle = it.next();
    driver.switchTo().window(wHandle);
    if (driver.getCurrentUrl().equals("https://uat.omnilife.com.au/OmniLifeWeb/#/quotes/300020fb-e61b-439a-b5d1-5459976ee59b?crmReferenceId=006p0000004VCAE&page=client&save=true&complete=true")) {
    {
        driver.findElement(By.xpath("//*[@id='client-occupation']")).sendKeys("Comput");
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(By.linkText("[ Computing Professional ]")).click();
        driver.findElement(By.xpath("//*[@id='update-client']")).click();
        driver.findElement(By.xpath("//*[@id='trmCheck']")).isSelected();
        driver.findElement(By.xpath("//*[@id='quote-settings']/div[1]/div[2]/div/div[1]/div[2]/input")).sendKeys("50000"); 
        driver.findElement(By.xpath("//*[@id='quoteResultGrid']/div/div[6]/div/div[1]/div/table/tbody/tr[1]/td[1]/div/input")).isSelected();
        driver.findElement(By.xpath("//*[@id='saveToCRMBulk']")).click();
    }
  }
        driver.switchTo().window(parentWindowHandle);
  • Can you provide the error message that you're getting? – Swagin9 Feb 14 '17 at 21:46
  • Maybe this @id='client-occupation' element is not text field but some element above it, or you have a frame that you need to switch to in the child window? – Asia Wawrzyczek Feb 15 '17 at 11:38
1
  • You haven't switched to the child window yet, because when you have used getWindowHnadles you will get all the current windows.
  • So when you are iterating, its still in the main window, and the element to enter data won't be there in the main window so that you will get an error.
  • use a condition so that it won't execute if handle is of main window. like this

    if(wHandle!=parentWindowHandle)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.