Selecting a nested iframe - selenium / javascript / node-js

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

For instance:

<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 that also failed.

Edit:

Ok, I get it, but my answer was deleted by @casparOne for some reason. If someone still wonders what the problem is here:

My code above works, not locally. Chrome's security settings refuse to go deeper into the iframe in the local file. Therefore, it did not even show the source code for the iframe.

+6
source share
1 answer

I have done this several times before. Try pausing 1 second between swtich frames. (Sometimes) you need to give Selenium (or the browser) enough time to load the DOM frame before you try another switch.

+3
source

Source: https://habr.com/ru/post/959385/


All Articles