0

I'm using selenium webdriver + jsoup in java for automation and parsing. Manually I can go on a website and open iframe in a new tab. I want to do this automatically.

I inspected the iframes on websites containing ads, these iframes have src attributre empty or blank. They contain iframes within them, which have src attribute set to, source of iframe. How can I get this URL through code?

I want to open a link, get all iframes, and output the source attribute of those iframes, those sources which firefox would refer me to, if I click "open frame in new tab"

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(200, TimeUnit.SECONDS);
String baseUrl = "https://www.iplocation.net/";

driver.get(baseUrl);
String source = driver.getPageSource();

List<Element> iframes = doc.getElementsByTag("iframe");
System.out.println("Number of iframes = "+ iframes.size());
System.out.println("URL of 1st iframe: " + iframes.get(0).attr("src”)); // empty
user3834119
  • 411
  • 9
  • 21

1 Answers1

0

I inspected the iframes on websites containing ads, these iframes have src attributre empty or blank. They contain iframes within them, which have src attribute set to, source of iframe. How can I get this URL through code?

Don't mix the code with Jsoup. Stay with Selenium API only. I can see two steps in this case:

  • Find the iframes having src attribute empty
  • Find inside those iframes the iframes having src attribute set to

See the question for details: How to handle iframe in WebDriver?

Community
  • 1
  • 1
Stephan
  • 41,764
  • 65
  • 238
  • 329
  • I know I'll have to go to nested iframes to get source. But what I wanted was a better way to get this or an algorithm to do this recursively maybe. – user3834119 Jun 30 '16 at 09:16