3

I am new to selenium and want to understand how to identify an element in an iframe or a pop up. In our app, when we click on a button, a popup or an iframe is loaded on the same page. on that page i need to click on a button and then continue my other actions. While recording, selenium is not waiting for the pop up or iframe to be loaded. It is going to the next command and failing because the object is not found as yet since the iframe/popup is still loading.

Should be using wait commands to wait for it to load or use some select commands.

I am confused. I tried couple of commands like, waitforpopup, selectframe, waitforframetoload, but could not figure out.

Any help on this would be great!

Thanks in advance

Emmanuel Angelo.R
  • 1,545
  • 2
  • 16
  • 24
Ani
  • 31
  • 1
  • 2

3 Answers3

4

Here's a solution that worked for me:

Scenario:

  1. Page loads with a JavaScript that adds an iframe to the DOM <iframe id="iframeId" />
  2. iframe loads
  3. Now I want to check for an element within the iframe <div id="divElement"></div>

Solution:

(Command > C, Target > T, Value > V) If I didn't include, it means leave it blank

  • C: open   |   T: /
  • C: waitForElementPresent   |   T: iframeId   |   V: 3000
  • C: waitForFrameToLoad   |   T: iframeId   |   V: 5000
  • C: selectFrame   |   T: iframeId
  • C: assertElementPresent   |   T: css=div#divElement
  • C: verifyElementPresent   |   T: css=div#divElement
Calvin
  • 1,305
  • 8
  • 17
0

Manual IDE commands will need to be entered to complete your script.

To identify elements in a pop-up, you will need to use the 'selectPopup' command to focus into the pop-up.

To identify elements within an iframe, use the 'selectFrame' command and enter the iframe id into the Target parameter. Using the 'selectFrame' command without a target id may silently fail, depending on page structure (may have multiple iframes etc).

Hope this information helps.

Jackson Lee
  • 131
  • 3
0

There is couple of answers here which anyone can get benefit but sometimes iframe id can be dynamic because of different content from a specific link(for example different subscriptions paid or trial etc.) and giving a static id to a target would fail your test. Best case would be take a static attribute of iframe tag like class attribute so you can run your script every time.

Alper Silistre
  • 117
  • 2
  • 12