0 votes
1 view
in Devops and Agile by (25k points)

I'm trying to access elements that are present under <form> <iFrame> <form> elements </form> </iFrame> </form>.

Could you help me with accessing these 'elements', which I'm working with Selenium Webdriver and JAVA?

Issue Encountered: Able to reach the destination page (where the above elements are present), but those elements are not recognized with my code.

Overview of XML structure:


    <form action="https://abcd/efgh/" name="outerForm" method="post" target="iFrameTitle">

        <iframe width="700" height="600" src="" title="Frame for Java Test" name="iFrameTitle" scrolling="auto" frameborder="0">

            <form id="innerFormID" name="innerForm" action="/xxx/xxxx/yyyy/zzzz/" method="post" autocomplete="off">

                <fieldset id="ncDetailsInner">

                    <div id="element1">

                        <label for="label1">

                        <abbr title="Required field">*</abbr></label>

                        <input name="label2" type="text" maxlength="30" id="cardHolder" value="" >


                    <div id="element2">

                        <label for="label3">Label3 <abbr title="Required field">*</abbr></label>

                        <div id="element3">

                            <label for="label4">Label4<abbr title="Required field">*</abbr></label>

                            <input id="label5" name="labelname5" type="text" maxlength="19" value="">


                        <div id="element4">

                            <label for="label6">Label6</label>

                            <input id="label7" name="labelname7" type="text" size="2" maxlength="2" value="" class="text disabled" disabled="">








Code Extract:

WebDriverWait wait_iframe = new WebDriverWait(driver, 20000);


calling_function(sh1.getCell(col + 10, row).getContents(), 

                sh1.getCell(col + 11, row).getContents(),

                sh1.getCell(col + 12, row).getContents(), 

                sh1.getCell(col + 14, row).getContents());                      

public static void called_funciton(String string1, String string2,

        String string3, String string4) {

        driver.findElement(By.name("Element1 Name")).sendKeys(string1);

        driver.findElement(By.id("Element2 ID")).sendKeys(string2);

        driver.findElement(By.id("Element3 ID")).sendKeys(string3);

        driver.findElement(By.id("Element4 ID")).sendKeys(string4);



Do let me know if require any further details!

1 Answer

0 votes
by (63.3k points)

When using an iframe, you will first have to switch to the iframe, before selecting the elements of that iframe

You can do it using:

driver.switchTo().frame(driver.findElement(By.id("frameId"))); //do your stuff driver.switchTo().defaultContent();

 In case if your frameId is dynamic, and you only have one iframe, you can use something like:


Hope this helps!


Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !