title: Accessing elements inside iFrame documents in Selenium WebDriver
body: <p>I am trying to automate a scenario where I would need to access elements inside an iFrame and continue my testing.
  My current problem is that, I am able to switch to the iframe successfully, but I am unable to access contents inside the frame. 
  The contents inside the iframe are Shadow DOM contents and are inside a document.</p>
  
  <p>The HTML code looks like this::(Please see attached<a href="https://i.stack.imgur.com/SB4QJ.jpg" rel="nofollow noreferrer">HTML</a>)</p>
  
  <p>I have tried the below and get 
  org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element</p>
  
  <ol>
  <li><p>By accessing the shadow root</p>
  
  <pre><code>driver.switchTo().frame("iframe_id");    
  WebElement root1 = driver.findElement(By.className("class_abs"));          
  WebElement shadowRoot1 = expandRootElement(root1);   
  </code></pre>
  
  <p>Here webdriver is unable to find element by classname.</p></li>
  </ol>
  
  <p>2.By using Javascript executor</p>
  
  <pre><code>driver.switchTo().frame("iframe_id");        
  JavascriptExecutor js=(JavascriptExecutor) driver;        
  js.executeScript("arguments[0].click();",  driver.findElement(By.xpath("button_xpath")));
  </code></pre>
  
  <p>Here webdriver is unable to access the Xpath.  </p>
  
  <p>3.
  Using normal Xpath after switching to IFrame.</p>
  
  <p>I would like to know if I need to access the contents of the document inside iFrame first to access its elements. If that is the case, how can I do it.        </p>
  
  <p>P.S- Tried this on both chrome and Firefox browser.</p>