I am trying to switch to iframe with dynamic iframe id. However, error out as below. Any help will be appreciate.
org.openqa.selenium.NoSuchFrameException: No frame element found by name or id iframe-8c590576-9047-4baf-a34f-69fe67a295a1
Following are my HTML out of following first iframe that I want to switch:
<iframe allowtransparency="true" class="iframe-4be2b789-7f13-4350-9771-0523258c080e contentPanelFrame" data-content-url="en_US/Person_homePagePDCPage.do?o3ctx=4096&concernRoleID=-8841741561699565568&evidenceType=null" data-dojo-attach-point="frame" frameborder="0" id="iframe-4be2b789-7f13-4350-9771-0523258c080e" iscpiframe="true" marginheight="0" marginwidth="0" title="Content Panel - Home" src="en_US/Person_homePagePDCPage.do?o3ctx=4096&concernRoleID=-8841741561699565568&evidenceType=null"> </iframe>
<iframe allowtransparency="true" class="iframe-8e82cd97-893d-41ec-b2e5-c6151d6a34a6 contentPanelFrame" data-content-url="en_US/SCSysMAAdminHomePagePage.do?o3ctx=4096" data-dojo-attach-point="frame" frameborder="0" id="iframe-8e82cd97-893d-41ec-b2e5-c6151d6a34a6" iscpiframe="true" marginheight="0" marginwidth="0" title="Content Panel - Home" src="en_US/SCSysMAAdminHomePagePage.do?o3ctx=4096" cd_frame_id_="146a47c04d9f04d598ccfa3f99c1674d"> </iframe>
<iframe allowtransparency="true" class="iframe-f41ba74a-5362-41f5-977f-e144c8c7e4e2 contentPanelFrame" data-content-url="en_US/Person_search1Page.do?o3ctx=4096" data-dojo-attach-point="frame" frameborder="0" id="iframe-f41ba74a-5362-41f5-977f-e144c8c7e4e2" iscpiframe="true" marginheight="0" marginwidth="0" title="Content Panel - Home" src="en_US/Person_search1Page.do?o3ctx=4096"> </iframe>
<iframe allowtransparency="true" border="0" class="detailsPanelFrame iframe-ef98a903-a64e-4b67-bba1-46a86eb2569c" data-content-url="en_US/Person_homeTabDetailsPage.do?concernRoleID=-8841741561699565568&o3ctx=36864" frameborder="0" height="99%" page-id="Person_homeTabDetails" scrolling="no" width="99%" src="en_US/Person_homeTabDetailsPage.do?concernRoleID=-8841741561699565568&o3ctx=36864" title="Context Panel - Sharone Stone"> </iframe>
<iframe _srccontents="en_US/Participant_resolveParticipantSmartPanelPage.do?concernRoleID=-8841741561699565568&o3ctx=266240" allowtransparency="true" border="0" class="smartPanelFrame iframe-f9201550-6ac4-4916-9262-988c17c9a24d" frameborder="0" height="99%" id="curam_tab_SmartPanelIframe" iframeloaded="false" name="curam_tab_SmartPanelIframe" page-id="Participant_resolveParticipantSmartPanel" scrolling="no" src="" title="Smart Panel" width="99%"> </iframe>
<iframe allowtransparency="true" class="iframe-7c91f6ef-a3d3-460e-83b5-d405503921e3 contentPanelFrame" data-content-url="en_US/Activity_redirectCurrentUserCalendarPage.do?o3ctx=4096&startDate=null&calendarViewType=null" data-dojo-attach-point="frame" frameborder="0" id="iframe-7c91f6ef-a3d3-460e-83b5-d405503921e3" iscpiframe="true" marginheight="0" marginwidth="0" title="Content Panel - Home" src="en_US/Activity_redirectCurrentUserCalendarPage.do?o3ctx=4096&startDate=null&calendarViewType=null"> </iframe>
<iframe id="ie-progress-indicator-helper" name="null" src="about:blank" onload="null" style="position: absolute; left: 1px; top: 1px; height: 1px; width: 1px; visibility: hidden" title="ie-progress-indicator-helper"></iframe>
<iframe id="ie-progress-indicator-helper" name="null" src="about:blank" onload="null" style="position: absolute; left: 1px; top: 1px; height: 1px; width: 1px; visibility: hidden" title="ie-progress-indicator-helper"></iframe>
<iframe id="ie-progress-indicator-helper" name="null" src="about:blank" onload="null" style="position: absolute; left: 1px; top: 1px; height: 1px; width: 1px; visibility: hidden" title="ie-progress-indicator-helper"></iframe>
Following are my code:
driver.switchTo().frame("iframe-8c590576-9047-4baf-a34f-69fe67a295a1");
Thread.sleep(2000);
I tried using the xpath as below however no luck:
driver.findElement(By.xpath("//html/body/div[1]/div[4]/div[3]/div[2]/div[3]/div[3]/div[2]/div/div[4]/div/div/div[1]/div/div[3]/div/div[2]/iframe/html/body/div[2]/div[6]/div/table/tbody/tr/td[1]/div/div/table/tbody/tr/td[1]/[contains(@class, 'field-link') and contains(@class ,'external-link')]")).click();
Thread.sleep(2000);
You can locate the iframe
as web element using partial id or class and use it to switch.
It looks like the src
attribute is unique. You can use it to locate the frame.
WebElement iframe = driver.findElement(By.cssSelector("[src*='en_US/Person_homePagePDCPag']"));
driver.switchTo().frame(iframe);