YuGO
YuGO

Reputation: 1

Selenium Web Driver - Unable switch to frame (Java)

Here is picture --- Beginning Page --- Page After Click on a button --I'm a beginner then I have a problem when I using

GetDriver().switchTo().frame(element) or ExpectedConditions.frameToBeAvailableAndSwitchToIt(element)

Here is the HTML:

<head id="ctl00_Head1">
<body>
<div id="divPleaseWait" style="display: none"/>
<div>
<a>
<div style="position: absolute; visibility: hidden;">
<div id="TB_overlay" class="TB_overlayBG"/>
<div id="TB_window" style="margin-left: -440px; width: 880px; margin-top: -295px; display: block;">
<div id="TB_title">
<iframe id="TB_iframeContent" frameborder="0" style="width:879px;height:562px;" onload="tb_showIframe()" name="TB_iframeContent303" src="CompanyDetail.aspx?" hspace="0"/>
</div>

And my code is

WebDriverWait wait = new WebDriverWait(GetDriver(), time_out);
        wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.Id("TB_iframeContent")));

or

GetDriver().switchTo().frame(By.Id("TB_iframeContent"));

but I unable switch to that iframe and located the id in that iframe This is my error out

Timed out after 30 seconds waiting for frame to be available: [[FirefoxDriver: firefox on WINDOWS (fd412e93-d76e-4934-9fa5-a771c836ffe3)] -> id: TB_iframeContent] Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03' System info: host: 'ABCV-VN-01-PC', ip: '192.168.3.30', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_51' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=47.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: fd412e93-d76e-4934-9fa5-a771c836ffe3 Unable to locate element: {"method":"id","selector":"ctl00_adminMenuCompany"}

Could you please help me?!? I really mad for it!!!!

Thank you all for supporting. I find that my firefox driver is error with this issue. When I try with chrome driver, It's OK. I think I should update to selenium 3.0

Upvotes: 0

Views: 1716

Answers (1)

JeffC
JeffC

Reputation: 25542

My guess is that maybe the IFRAME you are looking for is nested inside another IFRAME? Run this code and see if the IFRAME you are looking for is present in the list.

driver.findElement(locator).click(); // click the button to make the IFRAME visible
// you may need a wait here
List<WebElement> iframes = driver.findElements(By.tagName("iframe"));
for (WebElement iframe : iframes)
{
    System.out.println(iframe.getAttribute("outerHTML"));
}

EDIT:

Have you tried using a frame index? Try the below.

driver.findElement(locator).click(); // click the button to make the IFRAME visible
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(0));

I would suggest that if the above doesn't work, I would put a breakpoint on the line after you click the button that exposes the IFRAME and inspect the page. Something weird is going on. I don't suppose you can post a link to the page?

Upvotes: 0

Related Questions