1

I have html page like below and I need to click on Login inside the class clslogin.

How do I traverse to find the Login. I'm using C# with selenium Webdriver.

With XPath (/html/body/div/table/tbody/tr[1]/td[3]/a) I'm not getting control on Login class, always element not found error is throwing. Can anybody help me to get exact xpath.

<html>
 <head></head>
 <frameset name="mytestTopFrame" rows="*"......  >
  <frame name="mytestTopsubframe" src="index.html" width="100%"......... >
   <html>
    <head></head>
     <frameset name="mytest" rows="70,20..."......  >
       <frame name="mytestsubframe" src="menu.html" width="100%"......... >
       <html>
        <body class="clsmenu" .......>
         <div align="left">
           <table id="Title" ......>
            <tbody>
             <tr class="toptitle" ...>
              <td class="clicklogin" ....>
               <a class="clslogin" href="linkref">Login </a>
              </td>
             </tr>
            </tbody>
          </table>
         </div>
        </body>
       </html>
      </frame>
    </frameset>
   </html>
  </frame>
 </frameset>
</html>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
shivappa
  • 153
  • 1
  • 11

2 Answers2

1

As per the HTML you have shared to click on the element with text as Login you have to induce WebDriverwait twice to switch through 2 child frame and then again to locate the desired element as follows:

//SwitchTo mytestTopsubframe
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Name("mytestTopsubframe")));
//SwitchTo mytestsubframe
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Name("mytestsubframe")));
//Locate the desired element
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[@class='clslogin' and @href='linkref']"))).Click();

Note: You don't have to consider the presence of <frameset> and can safely ignore those tags.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Still not able to get to Login. For each frame me getting 'No such frames' error. Is it an issue with browser bcz I'm using Firefox current latest version 'Quantum'. – shivappa Jul 25 '18 at 06:03
  • Sorry, I was not setting to DefaultContent() before switching to frames. Thanks it worked for me. +1 – shivappa Jul 30 '18 at 11:10
  • Another update. above code working only on IE11 version-11.492. 'Nosuchframe' exception on Firefox, Chrome latest versions. Any idea why ? – shivappa Jul 31 '18 at 04:20
0

You need to first change to the correct iframe to access the path who are below the iframe. For that you can use driver.SwichtTo().Frame("your frame ID"). If this solution does not work, in this thread may be a solution the thread uses the same lines of code but it search for the parent and child nodes

Gsanez
  • 61
  • 6
  • Unfortunately I don't have "id" attribute in frameset. Instead I have "name" attribute, from which I still not getting control to go inside the frame. I used By.Name("mytestTopFrame") to switch to the frame. Is it possible to switch to frame using "name" attribute ? – shivappa Jun 12 '18 at 09:15
  • Yep, it uses "By", you can use it with xpath, name, id or whatever you need. – Gsanez Jun 12 '18 at 10:28