Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium IE Webdriver中switchTo()之后查找元素时出现问题_Java_Selenium Webdriver - Fatal编程技术网

Java Selenium IE Webdriver中switchTo()之后查找元素时出现问题

Java Selenium IE Webdriver中switchTo()之后查找元素时出现问题,java,selenium-webdriver,Java,Selenium Webdriver,您好,在IE Webdriver中执行切换到(新句柄)后,我在尝试在新窗口中查找元素时遇到了问题 我使用的代码是 WebDriver driver = new InternetExplorerDriver(); //some code String winHandleBefore = driver.getWindowHandle(); //store the current window handle driver.findElement(By.name("element1")).cli

您好,在IE Webdriver中执行
切换到(新句柄)
后,我在尝试在新窗口中查找元素时遇到了问题

我使用的代码是

WebDriver driver = new InternetExplorerDriver();

//some code

String winHandleBefore = driver.getWindowHandle();  //store the current window handle

driver.findElement(By.name("element1")).click();  //opens a new window

//code to find the new window handle

driver.switchTo().window(NewWindowHandle);   //switch to new window 

String url = driver.getCurrentUrl();    //returns me the URL of the newly opened window

driver.findElement(By.name("element2")).click();  //click on element in new window
切换窗口后,
findElement()
无法找到新元素,而新窗口的url显示正确。 我还执行了一个
driver.getTitle()这也为我提供了新打开窗口的正确页面标题

我交叉验证了元素属性,这是正确的


有人能帮我吗?

试试这个它对我很有用:

 for(String NewWindowHandle:driver.getWindowHandles())
 {
    driver.switchTo().window(NewWindowHandle);   //switch to new window 
 }

新窗口中的元素是否存在于任何帧中?是否尝试了等待调用?可能是加载该元素需要时间。@HemChe:不,该元素不在框架内。@grm:是,等待浏览器加载被调用。@preeth您是否尝试过使用css或xpath等不同的定位器来定位该元素?我认为这对操作没有帮助;他们对switchTo()调用没有问题,它试图在switchTo()之后定位元素,这是错误的。开关工作正常。在新窗口中搜索元素时,问题是