如何在硒中切换到iframe [英] How to switch to Iframe in selenium

查看:88
本文介绍了如何在硒中切换到iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现很难输入iframe上存在的用户名和密码,当我们单击登录链接时,该用户名和密码就会弹出.

I am finding difficult to enter the user name and password present on the iframe which gets popped up when we click on the signin link.

有人可以帮我吗?

下面给出的网站链接

链接: http://cashkaro.iam Savings.co.uk/

关于

推荐答案

Please find the answer below 

public void login_normally() {
        
        navigate_to_url(prop.getProperty("url_prod_Locale"));
        // Parent window
        String parent_window = driver.getWindowHandle();
        System.out.println("Parent windiow :" + parent_window);

        driver.findElement(By.xpath(prop.getProperty("singin_link"))).click();

        WebDriverWait wait = new WebDriverWait(driver, 7);
          String iframe_xpath = prop.getProperty("iframe_com_xpath");
        wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By
                .xpath(iframe_xpath)));

        driver.findElement(By.xpath(prop.getProperty("email_id_InSignIn")))
                .sendKeys(prop.getProperty("user_email_id_signIn"));
        driver.findElement(By.cssSelector(prop.getProperty("password_InSign")))
                .sendKeys(prop.getProperty("pwd_signIn"));

        boolean check_box_flag = driver.findElement(
                By.xpath(prop.getProperty("Keep_me_signed_in"))).isSelected();
        System.out.println("check_box_flag" + check_box_flag);

        if (check_box_flag == false) {
            driver.findElement(By.xpath(prop.getProperty("Keep_me_signed_in")))
                    .click();
        }

        driver.findElement(By.xpath(prop.getProperty("sign_button_signIn")))
                .click();
 //=================================================================================
/*      String login_mesg_error = driver.findElement(
                By.cssSelector(prop.getProperty("loginerror"))).getText();
        System.out.println(" login Error : " + login_mesg_error);
        
            
        if (login_mesg_error.length()<0 ) {
            System.out.println("Sucessfully Loggedin");
            Assert.assertTrue(true, "Sucessfull Login");
            APPLICATION_LOG.debug(login_mesg_error);
        } else {
            System.out.println("Login Failed");
            Assert.assertTrue(false, login_mesg_error);
            APPLICATION_LOG.debug(login_mesg_error);
        }*/
        
//==============================================================================
        String login_mesg_error=" ";
        List<WebElement> li=driver.findElements(By.cssSelector(prop.getProperty("logout_button_css")));
        System.out.println(" list size :" +li.size());
                
        if(li.size()>0)
        {
            System.out.println("Sucessfully Loggedin");
            Assert.assertTrue(true, "Sucessfull Login");
            APPLICATION_LOG.debug("Sucessfull Login");
        } else {
            login_mesg_error = driver.findElement(
                    By.xpath(prop.getProperty("login_error_mesg"))).getText();
            System.out.println(" login Error : " + login_mesg_error);
            System.out.println("Login Failed");
            Assert.assertTrue(false, "Login failed - Incorrect username or password");
            APPLICATION_LOG.debug(login_mesg_error + "Login failed");
        }
        driver.switchTo().defaultContent();
        
        
    }
    

这篇关于如何在硒中切换到iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆