如何在硒中的窗口之间切换(不是标签)
每当单击登录按钮时,打开一个新窗口(不是选项卡),我想切换到打开的窗口,这是我的代码,我的代码不正常(驱动程序不是切换到其他窗口)。
System.SetProperty(“ webdriver.chrome.driver”,“ C:\ Users \ atif.ali \ Desktop \ driver \ driver \ chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.get("https://release01.curemd.com/curemd/datLogin.asp");
//driver.get("https://release01.curemd.com/curemd/datCureMD.aspx");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"vchLogin_Name\"]")).sendKeys("zlive");
driver.findElement(By.xpath("//*[@id=\"vchPassword\"]")).sendKeys("1234");
//*[@id="frmLogin"]/div[3]/button
driver.findElement(By.xpath("//*[@id=\"frmLogin\"]/div[3]/button")).click();
String mainwindow = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
System.out.println(handles);
for(String handle:handles)
{
driver.switchTo().window(handle);
System.out.println(driver.getCurrentUrl());
}
driver.switchTo().window(mainwindow);
System.out.println(driver.getCurrentUrl());
Whenever login button is clicked a new window (NOT TAB) is opened I want to switch to opened window here is my code please me out its not working fine(driver is not switching to other window).
System.setProperty("webdriver.chrome.driver", "C:\Users\atif.ali\Desktop\Driver\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://release01.curemd.com/curemd/datLogin.asp");
//driver.get("https://release01.curemd.com/curemd/datCureMD.aspx");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"vchLogin_Name\"]")).sendKeys("zlive");
driver.findElement(By.xpath("//*[@id=\"vchPassword\"]")).sendKeys("1234");
//*[@id="frmLogin"]/div[3]/button
driver.findElement(By.xpath("//*[@id=\"frmLogin\"]/div[3]/button")).click();
String mainwindow = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
System.out.println(handles);
for(String handle:handles)
{
driver.switchTo().window(handle);
System.out.println(driver.getCurrentUrl());
}
driver.switchTo().window(mainwindow);
System.out.println(driver.getCurrentUrl());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试一下:
You can try this :