How to locate and click on an element which is nested within multiple frame and frameset through Selenium using Webdriver and C#

佐手、 提交于 2019-11-27 02:26:31

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!