您好我正在尝试切换iframe,但我不知道如何将其切换到此框架,因为它的id使用永远动态的yui,目前使用selenium和eclipse luna使用谷歌浏览器作为我的webdriver浏览器
<iframe class="dialog-iframe-node " frameborder="0" id="yui_patched_v3_11_0_1_1436845377989_182_iframe_" name="yui_patched_v3_11_0_1_1436845377989_182_iframe_" src="https://mo-sit.nets.com.sg/group/main/pr-enquiry?p_p_id=p2p_Procurement_Enquiry_WAR_morp2pportlet&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_p2p_Procurement_Enquiry_WAR_morp2pportlet_action=renderGRNApplicationsPopup&_p2p_Procurement_Enquiry_WAR_morp2pportlet_appNo=PR020150102506&yui_patched_v3_11_0_1_1436845377989_183=1436845380806" style="height: 351px; width: 1024px;"></iframe>
整个HTML
<!DOCTYPE html>
<html id="yui_patched_v3_11_0_1_1437015884634_696" class="aui ltr yui3-js-enabled gecko ltr js firefox firefox37 firefox37-0 win secure" lang="en-US" dir="ltr">
<div id="yui3-css-stamp" class="" style="position: absolute !important; visibility: hidden !important"></div>
<head>
<body id="yui_patched_v3_11_0_1_1437015884634_695" class="red yui3-skin-sam controls-visible guest-site signed-in private-page site">
<div class="yui3-widget-mask" style="position: fixed; width: 100%; height: 100%; top: 0px; left: 0px; z-index: 1202;"></div>
<div id="yui_patched_v3_11_0_1_1437015884634_782" class="yui3-widget modal yui3-widget-positioned yui3-widget-modal yui3-widget-stacked modal-focused yui3-dd-draggable yui3-resize" style="height: 400px; width: 1024px; left: 397.5px; top: 5.89999px; z-index: 1202;" tabindex="0">
<div id="yui_patched_v3_11_0_1_1437015884634_795" class="modal-content yui3-widget-stdmod yui3-widget-content-expanded">
<div id="yui_patched_v3_11_0_1_1437015884634_1144" class="yui3-widget-hd modal-header">
<div id="yui_patched_v3_11_0_1_1437015884634_1005" class="yui3-widget-bd modal-body dialog-iframe-bd" style="max-height: 400px; height: 351px; padding: 0px;">
<iframe id="yui_patched_v3_11_0_1_1437015884634_782_iframe_" class="dialog-iframe-node " frameborder="0" src="https://mo-uat.nets.com.sg/group/main/pr-enquiry?p_p_id=p2p_Procurement_Enquiry_WAR_morp2pportlet&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_p2p_Procurement_Enquiry_WAR_morp2pportlet_action=renderGRNApplicationsPopup&_p2p_Procurement_Enquiry_WAR_morp2pportlet_appNo=PR020150706783&yui_patched_v3_11_0_1_1437015884634_783=1437016436400" name="yui_patched_v3_11_0_1_1437015884634_782_iframe_" style="height: 351px; width: 1024px;">
<!DOCTYPE html>
<html class="aui ltr yui3-js-enabled gecko ltr js firefox firefox37 firefox37-0 win secure dialog-iframe-root-node" lang="en-US" dir="ltr" style="padding: 15px;">
</iframe>
<div id="yui_patched_v3_11_0_1_1437015884634_951" class="loadingmask yui3-widget component overlay overlaymask yui3-widget-positioned yui3-widget-stacked overlaymask-hidden" style="position: absolute; left: 0px; top: 0px; height: 351px; width: 1024px; z-index: 1000;">
</div>
</div>
<div class="yui3-resize-handles-wrapper">
</div>
<div id="yui_patched_v3_11_0_1_1437015884634_515" class="yui3-dd-shim" style="top: 0px; left: 0px; position: absolute; z-index: 9999; overflow: hidden; background-color: red; display: none; height: 5px; width: 5px;"></div>
<div id="yui_patched_v3_11_0_1_1437015884634_222" class="yui3-widget modal yui3-widget-positioned yui3-widget-modal yui3-widget-stacked yui3-dd-draggable yui3-resize modal-hidden" style="height: 400px; width: 1024px; left: 2921px; top: 1107px; z-index: 1201;" tabindex="0">
<div id="yui_patched_v3_11_0_1_1437015884634_237" class="modal-content yui3-widget-stdmod yui3-widget-content-expanded">
<div id="yui_patched_v3_11_0_1_1437015884634_474" class="yui3-widget-hd modal-header">
<div id="yui_patched_v3_11_0_1_1437015884634_611" class="yui3-widget-bd modal-body dialog-iframe-bd" style="max-height: 400px; height: 351px; padding: 0px;">
<iframe id="yui_patched_v3_11_0_1_1437015884634_222_iframe_" class="dialog-iframe-node " frameborder="0" src="https://mo-uat.nets.com.sg/group/main/pr-enquiry?p_p_id=p2p_Procurement_Enquiry_WAR_morp2pportlet&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_p2p_Procurement_Enquiry_WAR_morp2pportlet_action=renderGRNApplicationsPopup&_p2p_Procurement_Enquiry_WAR_morp2pportlet_appNo=PR020150706784&yui_patched_v3_11_0_1_1437015884634_223=1437015894284" name="yui_patched_v3_11_0_1_1437015884634_222_iframe_" style="height: 351px; width: 1024px;">
<div id="yui_patched_v3_11_0_1_1437015884634_420" class="loadingmask yui3-widget component overlay overlaymask yui3-widget-positioned yui3-widget-stacked overlaymask-hidden" style="position: absolute; left: 0px; top: 0px; height: 0px; width: 0px; z-index: 1000;">
</div>
</div>
<div class="yui3-resize-handles-wrapper">
</div>
<a id="skip-to-content" href="#main-content">Skip to Content</a>
<div id="yui_patched_v3_11_0_1_1437015884634_729" class="wrapper">
</body>
</html>
答案 0 :(得分:0)
如果页面上只有一个框架,您可以使用以下代码(在Python上)
driver.switch_to.frame(driver.find_element_by_xpath("//iframe"))
在一般情况下,你应该找到这个框架的一些独特特征,例如,它可以是具有唯一id等的另一个元素的子元素