0

Using Selenium 4.0 and Google Chrome 142 in a C# application, I have issues accessing resp. "finding" an element on my website. The HTML presented in the Chrome dev console is as follows (slightly shortened, anonymized and compacted):

<iframe id="mainframe" name="mainframe" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0" width="100%" allowtransparency="true" onattributes="{"onload":"onLoadExzContentGetted(undefined);stopPerformanceMeasures();"}" style="visibility: visible; display: block; width: 890px; height: 561px;">
#document (https://example.org)
<html>
   <head>text skipped, title and several metas and scripts tags</head>
   <body marginwidth="0" marginheight="0" style="background-color: transparent; margin: 0px;">
      <div id="WzTtDiV" style="visibility: hidden; position: absolute; overflow: hidden; padding: 0px; width: 0px; left: 0px; top: 0px;"></div>
      <!-- I can't even find this element using FindElements, despite having switched to iFrame "mainframe" -->
      <span id="messagebox"> </span>
      <form name="GetInstructionOverviewActionForm" method="post" action="/example/getInstructionOverview.do" id="productOverviewForm">
         <div class="cuiSwitchColor uwrNoFolderLines uwrNoTreeFolders">
            <div class="cuiSwitchColor" id="ttOverview_container">
               <table cellpadding="0" cellspacing="0" style="width:890px;" id="ttOverview_headingtable" class="uwrNoFolderLines uwrNoTreeFolders uwrTable uwrTableLayoutFixed uwrTreeTable">
                  <colgroup>
                     <col width="250">
                     <col width="40">
                     <col width="180">
                     <col width="40">
                     <col width="380">
                  </colgroup>
                  <tbody>
                     <tr class="uwrTableTitle" id="ttOverview_title">
                        <td class="uwrFirst uwrTb" colspan="5">
                           <div class="uwrTableTitlePadding">
                              <table style="width:100%;border:0px;" cellpadding="0" cellspacing="0" summary="">
                                 <tbody>
                                    <tr>
                                       <td class="uwrJustFormat">
                                          <div class="uwrTb">Blocks and instructions</div>
                                       </td>
                                       <td class="uwrJustFormat" style="text-align:right;">
                                          <script type="text/javascript" language="Javascript">
                                             function globalPrint(){ [........] }    
                                          </script>
                                          <a onmouseup="uwrResetImage(this);" onmouseout="uwrResetImage(this);" style="text-decoration: none;" onmousedown="uwrPressImage(this);" href="javascript:globalPrint();" title="Print" class="cuiLink">
                                             <script type="text/javascript" src="/example/uwFunctionIcon.js"></script>
                                             <!-- skipped some script tags -->
                                             <img src="https://example.org/print_active.gif" alt="example/print_active.gif" id="funciconGlobalPrint" title="Print" class="uwrFunctionIcon cuiTableFunctionIcon uwrFunctionIconInTitle">
                                          </a>
                                          <a onmouseup="uwrResetImage(this);" onmouseout="uwrResetImage(this);" style="text-decoration: none;" onmousedown="uwrPressImage(this);" href="https://example.org" title="Help" class="cuiLink" target="_blank">
                                             <script type="text/javascript">uwrRegisterImage260('funciconGlobalHelp', '/example/contextsens_help_active.gif', '/example/contextsens_help_pressed.gif', '/example/contextsens_help_inactive.gif', 'example/contextsens_help_toggle.gif');</script>
                                             <img src="/example/contextsens_help_active.gif" alt="example/contextsens_help_active.gif" id="funciconGlobalHelp" title="Help" class="uwrFunctionIcon cuiTableFunctionIcon uwrFunctionIconInTitle">
                                          </a>
                                       </td>
                                    </tr>
                                 </tbody>
                              </table>
                           </div>
                        </td>
                     </tr>
                     <tr id="ttOverview_heading" class="uwrTableHeading">
                        <td scope="col" class="uwrFirst uwrTb" style="width:250px;">
                           <div class="uwrTb">
                              <!-- skipped -->href="#" class="cuiLink"><img src="/example/0.gif" alt="Collapse all" style="border:0;" class="uwrTreeCollapseAllImage"></a> &nbsp;
                           </div>
                        </td>
                        <td scope="col" class="uwrTb" style="width:40px;">
                           <div class="uwrTb">&nbsp;</div>
                        </td>
                        <td scope="col" class="uwrTb" style="width:180px;">
                           <div class="uwrTb uwrCrop">Description</div>
                        </td>
                        <td scope="col" class="uwrTb" style="width:40px;">
                           <div class="uwrTb">CCY</div>
                        </td>
                        <td scope="col" class="uwrLast uwrTb" style="width:380px;">
                           <div class="uwrTb">Blocks and instructions</div>
                        </td>
                     </tr>
                  </tbody>
               </table>
               <div id="ttOverview_scrollablediv" class="uwrVerticalScrollBox" style="width: 889px; height: 40px;">
                  <table border="0" summary="" cellpadding="0" cellspacing="0" id="ttOverview" class="uwrTable" style="table-layout:fixed;width:873px;">
                     <colgroup>
                        <col width="250">
                        <col width="40">
                        <col width="180">
                        <col width="40">
                        <col width="363">
                     </colgroup>
                     <tbody>
                        <tr id="ttOverview_row0" class="uwrZebraOdd uwrTableRowHover">
                           <td id="ttOverview_row0_col0" class="uwrFirst uwrTb" style="width:250px;height:100%;">
                              <div class="uwrTb" style="height:100%;">[......]</div>
                           </td>
                           <td id="ttOverview_row0_col1" class="uwrTb" style="width:40px;height:100%;">
                              <div class="uwrTb"><button onblur="uwrHideMenu270(this, 'menuttnr', 150);[......]"</button></div>
                           </td>
                           <td id="ttOverview_row0_col2" class="uwrTb" style="width:180px;height:100%;">
                              <div class="uwrCrop uwrTdEllipsis uwrTb">&nbsp;</div>
                           </td>
                           <td id="ttOverview_row0_col3" class="uwrTb" style="width:40px;height:100%;">
                              <div class="uwrTb">&nbsp;</div>
                           </td>
                           <td id="ttOverview_row0_col4" class="uwrLast uwrTb" style="width:363px;height:100%;">
                              <div class="uwrTdEllipsis uwrTb">&nbsp;</div>
                           </td>
                        </tr>
                        <tr id="ttOverview_row1" class="uwrZebraOdd uwrTableRowHover uwrTableLastContentRow">
                           <td id="ttOverview_row1_col0" class="uwrFirst uwrTb" style="width:250px;height:100%;">
                              <div class="uwrTb" style="height:100%;">[............]</div>
                           </td>
                           <td id="ttOverview_row1_col1" class="uwrTb" style="width:40px;height:100%;">
                              <div class="uwrTb"><button onblur="uwrHideMenu270(this, 'menuttnp', 150);[......]"</button></div>
                           </td>
                           <td id="ttOverview_row1_col2" class="uwrTb" style="width:180px;height:100%;">
                              <div class="uwrCrop uwrTdEllipsis uwrTb">&nbsp;</div>
                           </td>
                           <td id="ttOverview_row1_col3" class="uwrTb" style="width:40px;height:100%;">
                              <div class="uwrTb">&nbsp;</div>
                           </td>
                           <td id="ttOverview_row1_col4" class="uwrLast uwrTb" style="width:363px;height:100%;">
                              <div class="uwrTdEllipsis uwrTb">
                                 <a href="javascript:expandNode("ttnp")" id="lttnp" class="cuiApplLink">Instructions</a> <!------- I want to access this element, and click on link "Instructions" -->
                              </div>
                           </td>
                        </tr>
                     </tbody>
                     <input name="actionType" id="actionType" type="hidden" value="">
                     <span id="sessionBeans">[...]</span>
                  </table>
                  <!-- [...] various input name fields -->
               </div>
            </div>
         </div>
         <!-- [...] various input name fields -->
      </form>
      <!-- [...] multiple script-tags -->
   </body>
</html>
</iframe>

The C# snippet used looks as follows:

try {
  WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); // default: 100 seconds
  w.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.Id("mainframe")));
} catch (Exception ex) {
  MessageBox.Show("MSG040: >" + ex.Message + "<", "", MessageBoxButtons.OK);
  meldung = "Left after MSG040";
  return;
}

try {
  driver.SwitchTo().Frame("mainframe");
} catch (Exception ex) {
  MessageBox.Show("MSG042: >" + ex.Message + "<", "", MessageBoxButtons.OK);
  meldung = "Left after MSG042";
  return;
}

try {
  WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); // default: 100 seconds
  w.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.Id("WzTtDiV")));
} catch (Exception ex) {
  MessageBox.Show("MSG044: >" + ex.Message + "<", "", MessageBoxButtons.OK);
  meldung = "Left after MSG044";
  return;
}

I can find the iframe "mainframe" just fine, see 1st line in HTML. Then I try to find (using Selenium.Waiter's ElementExists() method, which in essence calls the webdriver's FindElement() method) the element "WzTtDiV" as the first element after the "#document" entry, or the actually required element "lttnp", please see end of HTML snippet.

All hints and tricks found in various sources (ChatGPT, selenium.dev site, Stackoverflow, SauceLabs) tell me, that once I "switched" the current element to the iframe "mainframe" I should be able to "find" all following elements. However, the Wait always expires after timeout and triggers the last exception (MSG044) in the C# code snippet.

I'm under the vague impression that that "#document" entry is somehow blocking access the elements following it. I'm lost at what I'm doing wrong here. Any ideas what I can try?

Thank you very much for your support & Best regards

Volker


Update Dec 11th, 2025 Volker: Hi JeffC, I tried both of your suggestions to locate the element, however, both run into the wait timeout. Please find the stack traces, the full one for the ID method, and below just the first line of the trace for the XPATH method, as all the rest of the stack is identical.

I checked several times and the ID is constant and not auto-generated and always called "lttnp". All other preceeding lines of your code seem to work, the exception fires on the locating attempt of "lttnp". Is it normal that the selector is listed with a #-sign in the stack? --> "#lttnp"

Thank you for any further ideas!

Stack trace for locating by ID:

************** Exception Text **************

OpenQA.Selenium.WebDriverTimeoutException: Timed out after 10 seconds ---> OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#lttnp"}
  (Session info: chrome=142.0.7444.176); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
at OpenQA.Selenium.WebDriver.<ExecuteAsync>d__64.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.By.<.ctor>b__6_0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.WebDriver.FindElement(By by)
   at SeleniumExtras.WaitHelpers.ExpectedConditions.<>c__DisplayClass7_0.<ElementIsVisible>b__0(IWebDriver driver)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition, CancellationToken token)
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.Support.UI.DefaultWait`1.ThrowTimeoutException(String exceptionMessage, Exception lastException)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition, CancellationToken token)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at GPPReader.GPPReaderProcessing.LaunchGPPReader(String url) in C:\Dev\GPP-Reader\GPPReaderProcessing.cs:line 600
   at GPPReader.GPPReaderForm.Launch_GPPReader_UI() in C:\Dev\GPP-Reader\GPPReaderForm.cs:line 260
   at GPPReader.GPPReaderForm.BtnValidateData_Click(Object sender, EventArgs e) in C:\Dev\GPP-Reader\GPPReaderForm.cs:line 185
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Stack trace (first line only) when locating by XPATH, the rest of the trace is identical:

OpenQA.Selenium.WebDriverTimeoutException: Timed out after 10 seconds ---> OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//a[text()='Instructions']"}
2
  • Are your sure the element has the id WzTtDiV every time you load the page? That looks like it is dynamically generated. Commented Dec 9, 2025 at 14:56
  • Hi Corey, yes, I wondered about that strange id as well, but it's the same every time I inspect the page :-) Commented Dec 10, 2025 at 6:43

2 Answers 2

0

I would suggest you get rid of all try-catches and error handling. They will likely be hiding hints or the actual issue found in the exception messages, etc. Trim your code down to the simplest like the below,

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Id("mainframe")));
IWebElement link = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("lttnp")));
// IWebElement link = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//a[text()='Instructions']"))); // alternative locator
Console.WriteLine(link.Text);
// once done inside the IFRAME, switch back to the normal context
driver.SwitchTo().DefaultContent();

Run the above, as is. You'll obviously have to add code to navigate to the right page, etc.

NOTE: The ID of the desired element is lttnp not ttnp.

Double check the ID on each run... either you are trying to obscure the IDs or they might be randomly generated. If none of those work, try the alternative locator, the XPath.

Sign up to request clarification or add additional context in comments.

5 Comments

If this doesn't work, post the full stack trace.
Hi Jeff, thanks very much for your suggestion, I'll give it a try and let you know the outcome. And yes, "lttnp" is the ID, that was a typo here in SO (now fixed).
Hi JeffC, I tried both of your suggestions, however both time out at the wait for the element, the preceeding code got carried out fine, so we should be within the iframe when searching for "lttnp" (which is a constant ID, not auto-generated or changing). I've added the stack trace to the post, both are identical except for the first line. Sorry for the spreaded layout of the trace, but otherwise I always got the "code is not properly formatted" error :-). Many thanks for any more suggestions on how to tackle this!
Can you add the URL to the page? Something is going on here and I don't think we're going to figure it out without me seeing the page myself.
Unfortunately not, it's a company internal website and not accessible from outside. Even if we would have a video call I'm not allowed to show its contents to you. But thanks heaps for your efforts so far, much appreciated.
0

After trying some more stuff, I finally found the solution for this myself. I took the URL shown in the #document tag and navigated to it using driver.Navigate().GoToUrl(). Then I could search and find the elements within the iframe :-).

However, after all I couldn't use that solution in my automation as the URL shown in the #document tag was not accessible in any attribute of any element. I tried "document.baseURI" and all the similar URL attributes of all sorts. The problem is that it's not defined in the "src" attribute of the iframe but somehow dynamically created with some JavaScript code in the background.

But thanks again to Jeff and Corey for their contributions!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.