Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

enter image description here

I want to get an element's id attribute that is inside of an iframe through Java. How do I access an element inside of an iframe in Java?

share|improve this question
I am little worried to see what you are automating. – Tarun Dec 8 '13 at 16:41

In my experience the simplest way to manipulate elements inside of an iframe with web automation is to treat the iframe src URL as a separate page and call the driver to visit that URL instead of the parent page. From the example in the screenshot, I would have an automated step that would visit the URL in the src attribute of iframe#ComposeRteEditor_surface... (the actual src attribute wasn't visible in the screenshot), then I would call the appropriate step or findElement() function as normal.

share|improve this answer
Thanks for ur answer, I tried in the following way but i did not get the expected value. driver.switchTo().frame(driver.findElement("ComposeRteEditor_surface"))).f‌​indElement(By.tagName("img")).toString(); – user6258 Nov 8 '13 at 7:48
Instead of driver.switchTo() try using driver.get() with the src attribute as the URL parameter. Then you can use findElementById() as normal. – Francis Nov 8 '13 at 15:47
user6258, when you say you don't get the expected value, what do you get? Is there an exception? Is it having trouble finding the iframe? Is it finding the iframe but having trouble finding the element within it? Something else? – Sam Woods Nov 8 '13 at 17:58

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.