I am using selenium for testing the web pages. Now I am testing a webpage contain frame. The structure us following.
<frameset title="Application Content">
<frame name="main" src="qweMain.jsp?language=ENG" scrolling="no" title="Main Frame">
#document
<html>
<head> </head>
<body>
<div>
<ou-button img="ico-menu" id="menuButton" usage="toolbar" onclick="main.doClose();main.onTopMenuClick('CI_MAINMENU', event);" title="Menu (Ctrl+Alt+M)" role="button" tabindex="5" aria-label="Menu (Ctrl+Alt+M)" onkeypress="onButtonKeyPress(event)"><svg class="icon-standard-container icon-size-standard icon-toolbar-container icon-size-toolbar" style=""><use xlink:href="ouaf/assets/svgs/ico-menu.svg#icon"></use></svg></ou-button>
</div>
</body>
</html>
</frame>
<noframes>
Browser not supported
</noframes>
</frameset>
I am trying to get the menu button.
driver.findElement(By.xpath("//ou-button[@img='ico-menu']")).click();
But I am getting NoSuchElementException is happening. I search for the solution. So I got some ideas for this. Some developers recommend to switch the frame before access the element. I tried that too.
driver.switchTo().defaultContent();
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("/html/frameset/frame")));
driver.switchTo().frame(driver.findElement(By.xpath("/html/frameset/frame")));
But still I am getting the same error. Please let some ideas to resolve this issue.