gpt4 book ai didi

java - 在 IE Webdriver 中执行 switchTo(new Handle) 后,我遇到在新窗口中查找元素的问题

转载 作者:太空宇宙 更新时间:2023-11-04 12:06:32 25 4
gpt4 key购买 nike

我从主函数中获取帐户的值。我认为该元素位于框架内。你能帮我一下吗?

我正在使用的代码是

public static void FSVLogin(WebDriver driver){

try{

driver.findElement(By.xpath("//*[@id='loginMode_6']")).click();
Thread.sleep(3000);

driver.findElement(By.xpath("//*[@id='btnLaunch']")).click();
Thread.sleep(6000);

switchwindow(driver);

}catch(Exception e){
System.out.println(e);

}

}



public static void switchwindow(WebDriver driver){

//Get all window handles
Set<String> allHandles = driver.getWindowHandles();

//count the handles Here count is=2
System.out.println("Count of windows:"+allHandles.size());

//Get current handle or default handle
String currentWindowHandle = allHandles.iterator().next();
System.out.println("currentWindow Handle"+currentWindowHandle);

//Remove first/default Handle
allHandles.remove(allHandles.iterator().next());

//get the last Window Handle
String lastHandle = allHandles.iterator().next();
System.out.println("last window handle"+lastHandle);

//switch to second/last window, because we know there are only two windows 1-parent window 2-other window(ad window)
driver.switchTo().window(lastHandle);
System.out.println(driver.getTitle());

}


public static void LoadAccountCase(WebDriver driver,String account,String caseid){


try{
System.out.println("inside account case load function");

//WebElement card=driver.findElement(By.xpath("//*[@id='txtCardNumber']"));
String id="txtCardNumber";
waitForPageLoad(driver,id);
driver.findElement(By.id("txtCardNumber")).click();
driver.findElement(By.id("txtCardNumber")).sendKeys(account);

}catch(Exception e){
System.out.println(e);

}



}

最佳答案

如果新窗口中的元素位于框架内,那么您首先需要切换到框架,然后找到该元素。

frame = driver.findElement(by.id("id of the frame"));
driver.switchTo().frame(frame);

/*To switch back to the page use*/
driver.switchTo().defaultContent();

关于java - 在 IE Webdriver 中执行 switchTo(new Handle) 后,我遇到在新窗口中查找元素的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40299483/

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