我需要在框架WorkAreaFrame1下单击id =“C4_W14_V15_ZSLS-ACC”。但我无法切换框架。获取错误消息为无法找到框架:WorkAreaFrame1。请帮忙。
我从父窗口打开了一个新窗口。在子窗口中,我需要在框架WorkAreaFrame1下单击id =“C4_W14_V15_ZSLS-ACC”。我无法使用以下代码进行clcik。
driver.switchTo().defaultContent();
driver.switchTo().frame("WorkAreaFrame1");
driver.findElement(By.id("C4_W14_V15_ZSLS-ACC")).click();
HTML代码
<head></head>
<frameset border="0" framespacing="0" rows="42,*">
<frame id="HeaderFrame" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" noresize="noresize" title="" name="HeaderFrame" src="/sap/bc/bsp/sap/crmcmp_hdr/bspwdapplication.do?></frame>
<frameset id="contentFrameset" border="0" framespacing="0" rows="*,0">
<frame id="WorkAreaFrame1"oaded('WorkAreaFrame1');" title="" name="WorkAreaFrame1" src="BSPWDApplication.do?crm-ext-integration=true&sap-client=300&…%2e00&sap-language=EN&sap-tray-padding=X&sap-tray-type=PLAIN" fsinit="loaded">
#document
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" style="height:100%;" webdriver="true">
<head></head>
<body>
<script type="text/javascript"></script>
<script type="text/javascript"></script>
<script type="text/javascript"></script>
<script src="/sap(====)/bc/bsp/sap/gsbirp/biframecontroller.js?sap-client=300&sap-language=EN&sap-domainRelax=min" type="text/javascript"></script>
<div id="submitInProgress" class="th-sip" style="display:none;position:absolute;padding-top:15px;height:65px;"></div>
<script type="text/javascript"></script>
<form id="myFormId" action="/sap(bD1FTiZjPTMwMCZpPTEmZT1WMU5NVkVVeE1UQmZYMTlmTVRRMU56ZGZ…%2e00&sap-language=EN&sap-tray-padding=X&sap-tray-type=PLAIN" method="post" name="myFormId" target="WorkAreaFrame2">
<div id="htmlb_hidden_system_fields"></div>
<div style="display:none"></div>
<input id="wcf-secure-id" type="hidden" value="5C256D90A170A43A6866D59964334196" name="wcf-secure-id"></input>
<input id="thtmlbKeyboardFocusId" type="hidden" value="first_active_element_in_work_area" name="thtmlbKeyboardFocusId"></input>
<input id="thtmlbKeyboardSelectId" type="hidden" value="" name="thtmlbKeyboardSelectId"></input>
<script type="text/javascript"></script>
<div id="exceptionDisplayAreaDiv" class="th-msg-box" style="display:none;"></div>
<div id="rootAreaDiv" class="th-ajax-area">
<!--
Begin rootAreaDiv
-->
<script src="/sap(====)/bc/bsp/sap/crm_ui_start/crmuifClient.js" type="text/javascript"></script>
<script src="/sap(====)/bc/bsp/sap/uicmp_ltx/LaunchTransaction.js" type="text/Javascript"></script>
<div id="C1_W1_V2" tgt="" dhe="false">
<!--
Begin C1_W1_V2
-->
<table width="100%" cellspacing="0" cellpadding="0" style="table-layout:fixed;">
<tbody>
<tr></tr>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" style="table-layout:fixed">
<tbody>
<tr valign="top">
<td id="th_l_navcontainer" class="th-l-navcontainer">
<div id="th_l_navTop"></div>
<div id="C1_W1_V2_thescroll" class="th-sc-top" style="width: 172px; height: 344px;">
<div id="C1_W1_V2_thescroll_scbox" class="th-sc-container" style="width: 172px; height: 344px;">
<div id="C1_W1_V2_thescroll_sccontent" class="th-sc-content" style="width:172px;">
<div id="C1_W1_V2_$navbar" class="th-ajax-area">
<!--
Begin C1_W1_V2_$navbar
-->
<div id="C4_W14_V15" excevt="" intevt="c:C4_W14_V15:C1_W1_V2_C4_W14_V15_mainnavigationlinks.do;" automode="true" tgt="" dhe="true">
<!--
Begin C4_W14_V15
-->
<script type="text/javascript"></script>
<div id="C1_W1_V2_C4_W14_V15_mainnavigationlinks.do" class="th-ajax-area">
<!--
Begin C1_W1_V2_C4_W14_V15_mainnavigationlinks.do
-->
<ul id="C4_W14_V15_mainmenu" class="th-menu2" style="width:171px">
<li>
<a id="C4_W14_V15_SLS-HOME" class="th-lk" oncontextmenu="return false;" onfocus="thtmlbSaveKeyboardFocus('C4_W14_V15_SLS-HOME');" title="Home" onclick="htmlbSubmitLib('htmlb',this,'thtmlb:link:click:0','myFormId','C4_W14_V15_SLS-HOME','SLS-HOM-WC',0);return false" href="javascript:void(0)"></a>
</li>
<li class="th-menu2-sub-item">
<a id="C4_W14_V15_ZSLS-ACC" class="th-lk" oncontextmenu="return false;" onfocus="thtmlbSaveKeyboardFocus('C4_W14_V15_ZSLS-ACC');" title="Account Management" onclick="htmlbSubmitLib('htmlb',this,'thtmlb:link:click:0','myFormId','C4_W14_V15_ZSLS-ACC','SLS-ACC-WC',0);return false" href="javascript:void(0)"></a>
<div class="th-menu2-arrow"></div>
<ul class="th-menu2-sub"></ul>
</li>
<li class="th-menu2-sub-item">
Thanks Saravanan
答案 0 :(得分:0)
尝试删除该行:
driver.switchTo().defaultContent();
根据Javadocs,defaultContent()方法:
选择页面上的第一帧,或当页面包含iframe时的主文档。
这意味着它可能正在选择文档中的HeaderFrame,而您只想使用主文档。
答案 1 :(得分:0)
这可能晚了 7 年,但我认为这是 Charm,不是吗?
这是我个人用来浏览框架和使用内部元素的[使用最新技术:)]
var ifrm1 = document.getElementById('CRMApplicationFrame');
var doc = ifrm1.contentDocument?
ifrm1.contentDocument: ifrm1.contentWindow.document;
var ifrm2 = doc.getElementById('WorkAreaFrame1');
var doc = ifrm2.contentDocument?
ifrm2.contentDocument: ifrm2.contentWindow.document;
var area = doc.getElementById("thtmlbOverviewPageBox");
我注意到您要查找的 ID 是生成的 ID,这意味着它可以更改。您可能希望通过使用其他属性来查找它,或者使用最接近的常量 ID 容器,然后像这样查询部分 ID:[我们正在寻找的元素 ID:“C1_W1_V2_C1_W1_V2_V3_C26_W86_V88_aiccmcdoverview.do_0005”]
var trArea = area.querySelector("[id$='_aiccmcdoverview.do_0005']");