Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to select a nested iframe within an iframe with the selenium webdriver module in node-js.

For example:

<iframe id="firstframe">
   <div id="firstdiv"></div>
   <iframe id="secondframe">
     <div id="seconddiv"></div>
   </iframe>
</iframe>

for the node-js part:

driver.switchTo().defaultContent();
driver.switchTo().frame("firstframe");   // --> works
driver.switchTo().frame("secondframe");  // --> NoSuchFrameError


iframes = driver.findElements(webdriver.By.tagName('iframe')).then(function(elements){
            console.log(elements.length); // --> if I put this code before the switch to first frame output: 1, if I put it after output: 0)
            });

I tried using the index number but this also failed.

Edit:

Ok, I figured it out but my answer got deleted by user @casparOne for some reason. If anyone still wonders what the problem was here goes:

My code above works, just not locally. Chrome's security settings refuse to go deeper in an iframe on a local file. Hence it didn't even show the source code for the iframe.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
698 views
Welcome To Ask or Share your Answers For Others

1 Answer

I've done this kind of thing before a few times. Try putting a 1 second pause between the swtich frames. (Sometimes) you need to give Selenium (or the browser) enough time for the frame DOM to load before you try another switch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...