0

I've tried for adding a comment to another question but it shows me an error message for minimum 50 reputations required, so I've updated my code. Now, please help me on below scenario:

I've one dashboard page In the dashboard, I've grid view which listed users On click Username, it opens 'new window' on the same page with Username and Password fields Now I've to entered text in New window As per my code, it is not working, please help me

Code -

                System.setProperty("webdriver.chrome.driver", 
               "C:\\chromedriver_win32\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://web.mauditor.com/Login/SignIn");
    driver.manage().window().maximize();
    driver.findElement(By.id("UserName")).sendKeys("ajay0094");
    driver.findElement(By.id("Password")).sendKeys("12341234");
    driver.findElement(By.id("btnsubmit")).click();
    Thread.sleep(3000);
    driver.findElement(By.xpath("//*[@id=\'leftpaneldiv\']/ul/li[1]")).click();
    driver.findElement((By.cssSelector(".treeview > a:nth-child(1) > span:nth-child(1)"))).click();
    Thread.sleep(2000);
    driver.switchTo().frame(driver.findElement(By.id("usermgmtframe")));
    driver.findElement(By.id("txtName")).sendKeys("Joe");  
    Thread.sleep(3000);
    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div/div/div/div/form/div[2]/div/div[2]/div/div/div/table/tbody/tr/td[6]/a[4]/img")).click();
    String parent_window = driver.getWindowHandle();
    System.out.println("Parent Window ID is : "+parent_window);
    java.util.Set<String> allWindows = driver.getWindowHandles();
    int count = allWindows.size();
    System.out.println("Now Total Windows : "+count);
    for(String child_1:allWindows)
    if(parent_window.equalsIgnoreCase(child_1))
    driver.switchTo().window(child_1);
                System.out.println(driver.getTitle());
                String child1_window = driver.getWindowHandle();
                System.out.println("Child 1 Window ID is : "+child1_window);

                driver.findElement(By.id("modal-close")).click();
                driver.findElement(By.id("UserName")).sendKeys("AJAY");

   Output- Parent Window ID is : CDwindow-DD4195D132ED64B192AB85F0846D5699
   Now Total Windows : 1
   mAuditor - Manage Users
   Child 1 Window ID is : CDwindow-DD4195D132ED64B192AB85F0846D5699
    Exception in thread "main" org.openqa.selenium.NoSuchElementException: 
    no such element: Unable to locate element: 
    {"method":"id","selector":"modal-close"}
    (Session info: chrome=66.0.3359.181)

Please check.

ajay kumar
  • 73
  • 1
  • 9

1 Answers1

0

for modal-dialog popups u can switch to active element

driver.switchTo().activeElement();
Thread.sleep(2000);
driver.findElement(By.id("UserName")).sendKeys("jow");
bhupathi turaga
  • 297
  • 2
  • 16