[英]How to locate and click on an element which is nested within multiple frame and frameset through Selenium using Webdriver and C#
I have html page like below and I need to click on Login inside the class clslogin.我有如下所示的 html 页面,我需要在类 clslogin 中单击登录。
How do I traverse to find the Login.我如何遍历以找到登录名。 I'm using C# with selenium Webdriver.
我将 C# 与 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.使用 XPath (/html/body/div/table/tbody/tr[1]/td[3]/a) 我无法控制 Login 类,总是抛出 element not found 错误。 Can anybody help me to get exact xpath.
任何人都可以帮助我获得确切的 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>
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:根据您共享的HTML以单击带有文本的元素作为登录,您必须诱导WebDriverwait两次以切换 2 个子
frame
,然后再次定位所需的元素,如下所示:
//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.注意:您不必考虑
<frameset>
的存在,并且可以安全地忽略这些标签。
You need to first change to the correct iframe to access the path who are below the iframe.您需要先更改为正确的 iframe 才能访问 iframe 下方的路径。 For that you can use
driver.SwichtTo().Frame("your frame ID")
.为此,您可以使用
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如果此解决方案不起作用,则在此线程中可能是该线程使用相同代码行但它搜索父节点和子节点的解决方案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.