我已尝试为其他问题添加评论,但它向我显示了至少需要50个声誉的错误消息,因此我更新了我的代码。现在,请帮我解决以下问题:
我有一个仪表板页面 在仪表板中,我列出了列出用户的网格视图 点击用户名,即可打开新窗口'在用户名和密码字段的同一页面上 现在我在新窗口中输入了文字 根据我的代码,它不起作用,请帮助我
代码 -
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)
请检查。
答案 0 :(得分:0)
对于模态对话框弹出窗口,您可以切换到活动元素
driver.switchTo().activeElement();
Thread.sleep(2000);
driver.findElement(By.id("UserName")).sendKeys("jow");