title: Unable to click a button inside iframe which itself is inside shadow root in Selenium WebDriver using Java
body: <pre><code>driver.get(&quot;https://thesportstak.com/&quot;);
      
      Thread.sleep(4000);
      WebElement scrollStory = driver.findElement(By.xpath(&quot;//div[@id='story3']&quot;));
      
  
      WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(3));
      wait.until(ExpectedConditions.visibilityOf(scrollStory));
      JavascriptExecutor js = (JavascriptExecutor) driver;
      js.executeScript(&quot;arguments[0].scrollIntoView(true);&quot;, scrollStory);
  
      List&lt;WebElement&gt; homeStories = driver.findElements(By.xpath(&quot;//div[@class=\&quot;mainDiv \&quot;]&quot;));
      List&lt;WebElement&gt; homeStoriesptag = driver.findElements(By.xpath(&quot;//div[@class=\&quot;mainDiv \&quot;]//p&quot;));
  
  
      for (WebElement homeStoryp : homeStoriesptag) {
          System.out.println(&quot;getting home story p tag &quot; + homeStoryp);
          System.out.println(&quot;Text of home story &quot; + homeStoryp.getText());
      }
  
      WebElement firstStory =homeStories.get(3);
  
      firstStory.click();
      Thread.sleep(3000);
  
      WebElement shadow = driver.findElement(By
              .cssSelector(&quot;div[class=\&quot;i-amphtml-fill-content i-amphtml-story-player-shadow-root-intermediary\&quot;]&quot;));
      // This Element is inside single shadow DOM.
  
      SearchContext shadowroot = shadow.getShadowRoot();
      Thread.sleep(1000);
      WebElement iframe = shadowroot.findElement(By.cssSelector(&quot; div:nth-child(1) &gt; iframe:nth-child(3)&quot;));
      wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(iframe));
      
      
      List&lt;WebElement&gt; please = driver.findElements(By.xpath(&quot;//div[@class=\&quot;letterbox\&quot;]//p&quot;));
      System.out.println(please);
      
      WebElement nextbutton =driver.findElement(By.cssSelector(&quot;button[aria-label='Next page']&quot;));
      
      for(WebElement letterstory : please) {
          wait.until(ExpectedConditions.attributeToBeNotEmpty(letterstory,&quot;class&quot;));
          wait.until(ExpectedConditions.elementToBeClickable(nextbutton));
      
      ***nextbutton.click();*** ----&gt;&gt;&gt; 
  </code></pre>
  <p>I am trying to click the above button. Next button.click. I have tried both xpath and css selector to find the button.</p>
  <p>Also, I can only fetch the text from the first story above, the rest elemenets are present, but no text can be fetched from that. the p tag and the texts are present in the DOM and can be seen in the first story itself.  last line.</p>
  <p>Kindly help regarding the same.</p>
  <pre><code>        System.out.println(&quot;stories element &quot;+ letterstory);
          ***System.out.println(&quot;stories inside &quot;+letterstory.getText());***
      }
  </code></pre>