java - 切换到 iframe 时无法定位元素?
问题描述
- 登录后尝试通过奖励帐户通过 Facebook 登录我让 iframe 将用户与奖励帐户连接,我正在使用窗口处理程序来定位从该框架弹出的 facebook,然后它在登录后关闭,我返回 iframe 但无法找到元素在父窗口(iframe)上,当我切换回来时,我没有得到这样的元素
- 错误是:
org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//*[@id='errorData']"}
使用的代码
public void amberLoginWithFacebook(String username, String pass) throws InterruptedException { actions.driver.switchTo().defaultContent(); actions.driver.switchTo().frame(0); actions.clickOn(By.cssSelector(facebookBtn)); Thread.sleep(2000); Set<String> handler = actions.driver.getWindowHandles(); Iterator<String> loop = handler.iterator(); String parentWindow = loop.next(); String childWindow = loop.next(); actions.driver.switchTo().window(childWindow); if (actions.driver.getTitle().toLowerCase().equals(facebookWindowTitle)) { actions.setText(By.cssSelector(facebookEmail), username); actions.setText(By.cssSelector(facebookPass), pass); actions.clickOn(By.cssSelector(facebookLoginBtn)); Thread.sleep(2000); } actions.driver.switchTo().window(parentWindow); // i get the exception here if (actions.waitUntil(By.xpath("NonlinkedAccountError"), "presenceOfElement") != null) {setCountryCode(properties.getProperty("CountryCode")); setPhone(properties.getProperty("phone")); actions.clickOn(By.xpath(defaultBtn)); actions.clickOn(By.xpath(enterEmail)); setEmail(properties.getProperty("email")); }
解决方案
推荐阅读
- angular - 当有人添加新记录时,有什么方法可以更新 mat-table 数据源?
- python - 如何使用单一 RGB 颜色过滤图像?
- ios - 如何根据标题改变 BarButtonItem 的大小
- ruby-on-rails - 由于某种原因,我在 Rails 中的 yaml 文件中出现语法错误
- git - 无法在 Azure Devops 中恢复
- bash - 在 GNU makefile 中使用 bash 算术扩展
- c++ - 智能指针如何通过偏特化选择default_delete?
- asp.net - PopUp Modal ASP.NET Core MVC 中的预填充表单
- java - UDP中使用的DatagramPacket
- sql-server - 是否可以使用 Windows 身份验证通过 Python 连接到 SSAS 多维数据集?