切换至iframe时无法找到元素?

时间:2018-11-28 15:41:18

标签: java selenium iframe frames

  1. 尝试在登录后通过奖励帐户通过Facebook登录我使iframe将用户与奖励帐户连接起来,正在使用窗口处理程序来查找从该框架弹出的Facebook,然后在登录后关闭,我返回iframe但无法当我切换回原位时,在父窗口(iframe)上找到一个元素
  2. 错误是:
  

org.openqa.selenium.NoSuchElementException:无此类元素:无法   定位元素:{“方法”:“ xpath”,“选择器”:“ // * [@ id ='errorData']”}

  1. 使用的代码

    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"));
    }
    

Screenshot for the frame

0 个答案:

没有答案