gpt4 book ai didi

java - 专注于子窗口 - selenium

转载 作者:太空宇宙 更新时间:2023-11-04 13:07:24 26 4
gpt4 key购买 nike

使用下面的代码可以识别在父窗口上单击按钮后打开的子窗口,但无法与其交互。我无法获取子窗口中的按钮文本。

岛上没有错误,只是没有执行所需的操作。

我做错了什么?

Set<String> handles = driver.getWindowHandles();

String firstWinHandle = driver.getWindowHandle();

String secondWinHandle;

String winHandle=handles.iterator().next();

if (winHandle!=firstWinHandle){

//To retrieve the handle of second window, extracting the handle which does not match to first window handle

secondWinHandle=winHandle; //Storing handle of second window handle

//Switch control to new window

driver.switchTo().window(secondWinHandle);

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

By tipoTecnologia2 = By.cssSelector("[name='btnClose'][value='Fechar'][type='input']");
driver.findElement(tipoTecnologia2).click();

driver.switchTo().activeElement().sendKeys(Keys.TAB);



}

Window

最佳答案

  Set<String> handles = driver.getWindowHandles();

System.out.println("no of windows" +handles.size());

String firstWinHandle = driver.getWindowHandle();

String window1=handles.iterator().next();

String window2=handles.iterator().next();

if(window1.equals(firstWinHandle)){

System.out.println("in parent windows.. switiching to child");

driver.switchTo().window(window2);

}else{

driver.switchTo().window(window1);

System.out.println("switched to second window");

}

请尝试此操作并告诉我您是否可以切换到新窗口。我预计这里只有两个窗口

关于java - 专注于子窗口 - selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34290024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com