how to handle dynamically changing iframe id using selenium webdriver

1,871 views
Skip to first unread message

Jay Kosgi Sharaff

unread,
Apr 24, 2014, 2:48:16 AM4/24/14
to seleniu...@googlegroups.com

iframe id=pngNewCase1143241142570_IFrame., this id changes dynamically every time how can i handle this in selenium webdriver java I tried using driver.switchTo().frame(driver.findElement(By.xpath("Xpath of Iframe which changes dynamically"))); driver.switchTo().defaultContent(); but dint work for me

also tried driver.switchTo().frame(driver.findElement(By.Id("pngNewCase1143241142570_IFrame"))); driver.switchTo().defaultContent();

can anyone help me please

I am getting element not found exception 

Biswajit Samal

unread,
Apr 24, 2014, 7:18:46 AM4/24/14
to seleniu...@googlegroups.com
Hi Jay

you can try with xpath by following the annotation-->  driver.switchTo().frame(driver.findElement(By.xpath(//HTML tag[starts-with(@id,pngNewCase])));
                                                                             driver.switchTo().defaultContent();

DongXiang

unread,
Apr 24, 2014, 9:20:48 PM4/24/14
to seleniu...@googlegroups.com
Is there any rules for the dynamic id change? if yes, you can generate the id dynamically based on the rule. 

If no rule can found, does the location of the IFrame is fixed? if it is fixed, you can use XPATH to locate the iframe.

If above all not matched, how may iframes do you have on the web page and what's the position for this iframe.

you can search all iframe and select expect one by the position. of course, it is better to ask your developer to add a fix id or name on this iframe.

Best Regards,
--david


Date: Wed, 23 Apr 2014 23:48:16 -0700
From: j...@irslogics.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] how to handle dynamically changing iframe id using selenium webdriver
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/837d86f0-b53d-4301-ad59-09972fe74fde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Priyanshu Shekhar

unread,
Apr 25, 2014, 8:18:22 AM4/25/14
to seleniu...@googlegroups.com

If you are sure about the position of iframe then you can go with below code

             WebElement parentOfIframe = driver.findElement(By.xpath("xpath"));
            List<WebElement> framesToSelect= parentOfIframe.findElements(By.tagName("iframe"));

            driver.switchTo().frame(framesToSelect.get(0));  //If your required frame is at first position


Reply all
Reply to author
Forward
0 new messages