Selenium Webdriver-Unable to find any element inside second child iframe(having dynamic name)

Selenium Webdriver-Unable to find any element inside second child iframe(having dynamic name)

![**Child frames are having dynamic name/id**][1]

**Browser-IE8**

I have to find a prompt box inside the second child iframe.

the parent iframe is having fixed id.Able to find element inside that
using driver.switchTo().frame(0)

The first child iframe is having dynamic name/id.
cframe_ms_id59 .Only last part changes.i.e. id59
I am able to find this element using xpath
**driver.findElement(By.xpath(“//iframe[contains(@id, ‘cframe_ms’]”))**

But my prompt box having a textbox resides in the **Second Child iframe** **having dynamic name/id.**I am not able to enter inside this iframe** and not able to find any element inside that.

Aakash Default Asked on April 27, 2015 in Selenium WebDriver.
Add Comment
1 Answer(s)

You have two options here
– Try index of frame, it should be 2nd index . SwitchTo().Frame(index). This true if this iframe will remain here only.
– Try finding the element by Xpath and then get the attribute ID of the element and use it to switch

pseudo code
WebElement element = driver.FindElement(By.Xpath(<XPath of the iframe>));
String IFrameId = element.getAttribute(“id”);
Driver.SwitchTo().Frame(IFrameId );

Virender

Virender Singh Professor Answered on April 27, 2015.

Hi Virender,the first approach is working for me.Thanks for the suggestion.
Though using secind apprach cant find the xpath since the frame name and id is changing dynamically

on May 2, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.