我试图选择在同一窗口中生成的弹出窗口中的“无线”按钮。它不会生成任何iFrame,并且我无法在此 Wifi-Connect 窗口中找到任何元素。
有人有什么主意吗?
我尝试过
driver.find_element_by_xpath(".//*[@id='ext-gen1481']/div/li[2]/div/a"
我也尝试通过CSS。
我要选择的代码:
<img class="x-tree-node-icon nsm-wifi-icon-wireless" unselectable="on" src="/scripts/ext-3/resources/images/default/s.gif" alt=""/>
<a class="x-tree-node-anchor" tabindex="1" href="" hidefocus="on">
<span unselectable="on">Wireless</span>
HTML代码:
<document>
<html class=" ext-strict">
<head>
<body id="ext-gen3" class=" ext-gecko ext-gecko3 ext-linux syno-diskless router" style="background: transparent url("resources/images/theme/router/default_wallpaper/01.jpg?v=7742") no-repeat scroll center center / cover ;">
<img id="sds-wallpaper" style="visibility: hidden;"/>
<!-- Don't contain any text node to avoid IE insertBefore bug -->
<div id="sds-apply-preview-form" style="position: absolute; top: -10000px; left: -10000px;">
<script src="synodefs.cgi?v=1540399973" type="text/javascript"/>
<script src="/scripts/uistrings.cgi?lang=enu&v=1514770623" type="text/javascript"/>
<script src="/webfm/webUI/uistrings.cgi?lang=enu&v=1514770623" type="text/javascript"/>
<script src="uistrings.cgi?lang=enu&v=1514770623" type="text/javascript"/>
<script src="/scripts/prototype-1.7.2/prototype.js?v=1540399953" type="text/javascript"/>
<script src="/scripts/ext-3/adapter/ext/ext-base.js?v=1540399953" type="text/javascript"/>
<script src="/scripts/ext-3/ext-all.js?v=1540399953" type="text/javascript"/>
<script src="/scripts/ext-3/ux/ux-all.js?v=1540399953" type="text/javascript"/>
<script src="/scripts/scrollbar/flexcroll.js?v=1540399953" type="text/javascript"/>
<style type="text/css">.flexcroll-hide-default { overflow: hidden !important; } </style>
<script src="/synoSDSjslib/sds.js?v=1540399966" type="text/javascript"/>
<script src="desktop.js?v=1540399973" type="text/javascript"/>
<script type="text/javascript">SYNO.SDS.Session = { "configured" : true, "diskless" : true, "enable_syno_token" : "yes", "fullversion" : "1514764831", "hostname" : "SynologyRouter", "isLogined" : false, "lang" : "enu", "login_background_color" : "#FFFFFF", "login_background_enable" : false, "login_background_ext" : ".jpg", "login_background_hd_enable" : false, "login_background_pos" : "center", "login_background_seq" : 0, "login_background_type" : "fromDS", "login_enable_fp" : 0, "login_logo_enable" : false, "login_logo_ext" : ".jpg", "login_logo_pos" : "center", "login_logo_seq" : 0, "login_only_bgcolor" : false, "login_style" : "tpl1", "login_version_logo" : true, "version" : "1514764831" } ;</script>
<script type="text/javascript"/>
<div class="pre-load-x-window-br"/>
<div id="ext-comp-1002" class=" x-tip-invalid" style="position: absolute; z-index: 2147483647; visibility: hidden; display: none;">
<div id="ext-comp-1003" class="x-tip" style="position: absolute; z-index: 20002; visibility: hidden; width: 159px; left: 847px; top: 368px; display: none;">
<div id="sds-taskbar-shadow" style="visibility: visible;"/>
<div id="sds-taskbar" class="x-column-layout-ct">
<div id="sds-desktop" class="sds-desktop-view-show no-transition" tabindex="-1" style="height: 358px; width: 1301px; overflow-x: hidden; overflow-y: auto;">
<ul id="ext-gen142" class="sds-desktop-shortcut">
<div id="ext-gen190" class="x-window-proxy"/>
<div id="ext-comp-1101" class=" x-window sds-window-v5" style="position: absolute; z-index: 11000; visibility: hidden; left: 301px; top: 118px; width: 700px;">
<div id="ext-gen273" class="x-window-proxy"/>
<div id="ext-comp-1151" class=" x-window sds-window-v5 x-resizable-pinned" style="position: absolute; z-index: 11000; visibility: hidden; left: 40px; top: 40px; width: 600px;">
<div id="ext-gen448" class="x-window-proxy"/>
<div id="ext-comp-1237" class=" x-window sds-window-v5 x-window-noborder x-window-plain x-resizable-pinned" style="position: absolute; z-index: 11000; visibility: hidden; left: 70px; top: 70px; width: 800px;">
<div id="ext-gen1030" class="x-window-proxy" style="display: none;"/>
<div id="ext-comp-1563" class="x-window syno-app-nsm-wifi sds-window-v5 x-resizable-pinned active-win" style="position: absolute; z-index: 9033; visibility: visible; left: 80px; top: 17px; width: 1100px;">
<div class="x-window-tl">
<div id="ext-gen1020" class="x-window-bwrap">
<div class="x-window-ml">
<div class="x-window-mr">
<div id="ext-gen1023" class="x-window-mc">
<div id="ext-gen1021" class="x-window-body" style="width: 1100px; height: 563px;">
<div id="ext-comp-1564" class=" x-border-layout-ct" style="width: 1100px; height: 563px;">
<div id="ext-comp-1561" class=" x-panel syno-ux-modulelist x-panel-noborder x-tree x-border-panel scroll-at-top scroll-at-bottom scroll-at-left scroll-at-right" style="width: 234px; left: 0px; top: 0px;">
<div id="ext-gen1033" class="x-panel-bwrap">
<div id="ext-gen1034" class="x-panel-body x-panel-body-noheader x-panel-body-noborder flexcrollactive" style="padding: 0px 16px 0px 12px; width: 206px; height: 563px; overflow: hidden; border-width: 0px; position: relative; text-align: left;" tabindex="0">
<div id="ext-gen1034_mcontentwrapper" class="mcontentwrapper" style="width: 206px; height: 563px; top: 0px; left: -12px; border-bottom: 0px solid black; text-align: start; padding: 0px 16px 0px 12px; position: relative; overflow: hidden; z-index: 2;">
<div id="ext-gen1034_contentwrapper" class="contentwrapper" style="position: relative; top: 0px; width: 100%; display: block; padding: 0px; left: 0px;">
<ul id="ext-gen1035" class="x-tree-root-ct x-tree-arrows" style="width: 234px;">
<div class="x-tree-root-node">
<li id="ext-gen1379" class="x-tree-node">
<li class="x-tree-node">
<div class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on" ext:tree-node-id="SYNO.SDS.NSMWifi.Wireless.Main">
<span class="x-tree-node-indent"/>
<img class="x-tree-ec-icon x-tree-elbow" src="/scripts/ext-3/resources/images/default/s.gif" alt=""/>
<img class="x-tree-node-icon nsm-wifi-icon-wireless" unselectable="on" src="/scripts/ext-3/resources/images/default/s.gif" alt=""/>
<a class="x-tree-node-anchor" tabindex="1" href="" hidefocus="on">
<span unselectable="on">Wireless</span>
</a>
</div>
<ul class="x-tree-node-ct" style="display:none;"/>
</li>
<li class="x-tree-node">
<li class="x-tree-node">
<li class="x-tree-node">
</div>
</ul>
</div>
</div>
<div id="ext-gen1034_scrollwrapper" class="scrollwrapper" style="width: 234px; height: 563px; position: absolute; top: 0px; left: 0px;">
</div>
</div>
</div>
<div id="ext-comp-1562" class=" x-panel x-panel-noborder x-border-panel" style="left: 240px; top: 0px; width: 860px;">
</div>
</div>
</div>
</div>
</div>
<div id="ext-gen1022" class="x-window-bl x-panel-nofooter">
</div>
<a id="ext-gen1029" class="x-dlg-focus" tabindex="-1" href="#"/>
<div id="ext-gen1040" class="x-resizable-handle x-resizable-handle-north x-unselectable x-window-handle"/>
<div id="ext-gen1041" class="x-resizable-handle x-resizable-handle-south x-unselectable x-window-handle"/>
<div id="ext-gen1042" class="x-resizable-handle x-resizable-handle-east x-unselectable x-window-handle"/>
<div id="ext-gen1043" class="x-resizable-handle x-resizable-handle-west x-unselectable x-window-handle"/>
<div id="ext-gen1044" class="x-resizable-handle x-resizable-handle-northeast x-unselectable x-window-handle"/>
<div id="ext-gen1045" class="x-resizable-handle x-resizable-handle-northwest x-unselectable x-window-handle"/>
<div id="ext-gen1046" class="x-resizable-handle x-resizable-handle-southeast x-unselectable x-window-handle"/>
<div id="ext-gen1047" class="x-resizable-handle x-resizable-handle-southwest x-unselectable x-window-handle"/>
</div>
</div>
<div id="ext-gen76" class="sds-launch-icon-dragging-proxy x-dd-drag-proxy x-dd-drop-nodrop" style="position: absolute; z-index: 15000; visibility: hidden; left: 111px; top: 209px;">
<div id="sds-appview" class=" syno-sds-appview white-scrollerbar sds-desktop-view-animate x-hide-offsets" style="width: 1301px; height: 358px;" tabindex="-1">
<div id="ext-gen108" class="appview-icon-dragging-proxy x-dd-drag-proxy x-dd-drop-nodrop" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen122" class="appview-icon-dragging-proxy x-dd-drag-proxy x-dd-drop-nodrop" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-comp-1064" class=" sds-previewbox x-hide-display"/>
<div id="ext-comp-1067" class=" sds-searchbox x-hide-display sds-searchbox-init-state">
<div id="ext-gen156" class="nsm-home-device-list-dragged x-dd-drag-proxy x-dd-drop-nodrop" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen159" class=" x-panel sds-port-disabled-panel sds-tray-panel" style="position: absolute; z-index: 11000; visibility: hidden; left: -10000px; top: -10000px; width: 300px;">
<div id="ext-comp-1110" class=" x-panel sds-tray-panel" style="position: absolute; z-index: 11000; visibility: hidden; left: -10000px; top: -10000px; width: 340px;">
<div id="ext-comp-1125" class=" x-panel sds-notify-tray-panel" style="position: absolute; z-index: 11000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen300" class="x-dd-drag-proxy x-dd-drop-nodrop x-grid3-col-dd" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen302" class="col-move-top"/>
<div id="ext-gen303" class="col-move-bottom"/>
<div id="ext-comp-1151-rzproxy" class="x-resizable-proxy x-unselectable"/>
<div id="ext-comp-1160" class=" x-panel sds-tray-panel sds-filemonitor-tray-panel x-panel-noborder x-grid-panel syno-ux-gridpanel" style="position: absolute; z-index: 11000; visibility: hidden; left: -10000px; top: -10000px; width: 300px;">
<div id="ext-gen365" class="x-dd-drag-proxy x-dd-drop-nodrop x-grid3-col-dd" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen367" class="col-move-top"/>
<div id="ext-gen368" class="col-move-bottom"/>
<div id="ext-comp-1174" class=" x-panel sds-tray-panel sds-filemonitor-tray-panel x-panel-noborder x-grid-panel syno-ux-gridpanel" style="position: absolute; z-index: 11000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-comp-1184" class=" x-panel sds-tray-panel sds-filemonitor-tray-panel x-panel-noborder x-grid-panel syno-ux-gridpanel" style="position: absolute; z-index: 11000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-comp-1189" class=" x-panel sds-tray-panel sds-filemonitor-tray-panel x-panel-noborder x-grid-panel syno-ux-gridpanel" style="position: absolute; z-index: 11000; visibility: hidden; left: -10000px; top: -10000px; width: 300px;">
<div id="ext-gen429" class="x-dd-drag-proxy x-dd-drop-nodrop x-grid3-col-dd" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen431" class="col-move-top"/>
<div id="ext-gen432" class="col-move-bottom"/>
<div id="ext-gen536" class="x-dd-drag-proxy x-dd-drop-nodrop x-grid3-col-dd" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen538" class="col-move-top"/>
<div id="ext-gen539" class="col-move-bottom"/>
<div id="ext-gen556" class="x-dd-drag-proxy x-dd-drop-nodrop x-grid3-col-dd" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px;">
<div id="ext-gen558" class="col-move-top"/>
<div id="ext-gen559" class="col-move-bottom"/>
<div id="ext-comp-1237-rzproxy" class="x-resizable-proxy x-unselectable"/>
<div id="ext-gen591" style="position: absolute; left: -1000px; top: -1000px; visibility: hidden; font-size: 12px; font-style: normal; font-weight: 400; font-family: verdana,tahoma,arial,helvetica,sans-serif; line-height: 14px; text-transform: none; letter-spacing: normal; width: auto;"/>
<div id="ext-gen742" style="position: absolute; left: -1000px; top: -1000px; visibility: hidden; font-size: 12px; font-style: normal; font-weight: 700; font-family: verdana,tahoma,arial,helvetica,sans-serif; line-height: 20px; text-transform: none; letter-spacing: normal; width: auto;"/>
<div id="ext-comp-1563-rzproxy" class="x-resizable-proxy x-unselectable" style="z-index: 9037;"/>
<div id="ext-gen1158" style="position: absolute; left: -1000px; top: -1000px; visibility: hidden; font-size: 12px; font-style: normal; font-weight: 700; font-family: verdana,tahoma,arial,helvetica,sans-serif; line-height: 20px; text-transform: none; letter-spacing: normal; width: auto;"/>
</body>
</html>
</document>
这是实际的代码,是我只是不通过Firefox检查器查看页面源:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=11" />
<meta name="msapplication-TileImage" content="resources/images/icon_tile.png?v=4398" />
<meta name="application-name" content="Synology Router - SynologyRouter" />
<meta name="msapplication-TileColor" content="#246BB3"/>
<meta name="description" content="Synology Router provides a full-featured network attached storage (NAS) solution to help you manage, backup and share data among Windows, Mac and Linux easily." />
<meta name="keywords" content="Multitasking,Web Application,Personal Cloud" />
<link rel="shortcut icon" href="favicon.ico?v=4399" />
<link rel="shortcut icon" href="resources/images/icon_dsm_96.png?v=4398" sizes="96x96"/>
<link rel="shortcut icon" href="resources/images/icon_dsm_64.png?v=4398" sizes="64x64"/>
<link rel="shortcut icon" href="resources/images/icon_dsm_48.png?v=4398" sizes="48x48"/>
<link rel="shortcut icon" href="resources/images/icon_dsm_32.png?v=4398" sizes="32x32"/>
<link rel="shortcut icon" href="resources/images/icon_dsm_16.png?v=4398" sizes="16x16"/>
<title>Synology Router - SynologyRouter</title>
<link rel="stylesheet" type="text/css" href="/scripts/ext-3/resources/css/ext-all.css?v=1540399953" />
<link rel="stylesheet" type="text/css" href="/scripts/ext-3/resources/css/xtheme-gray.css?v=1540399953" />
<link rel="stylesheet" type="text/css" href="/scripts/ext-3/ux/ux-all.css?v=1540399953" />
<link rel="stylesheet" type="text/css" href="/synoSDSjslib/sds.css?v=1540399966" />
<link rel="stylesheet" type="text/css" href="resources/css/desktop.css?v=1540399973" />
<style type="text/css">
@import url("modules/MyDSCenter/style.css?v=1540399986");
@import url("modules/PhotoViewer/style.css?v=1540399986");
@import url("modules/NetworkTools/style.css?v=1540399973");
@import url("modules/LogCenter/style.css?v=1540399971");
@import url("modules/nsm-AdminCenter/style.css?v=1540399982");
@import url("modules/nsm-Home/style.css?v=1540399967");
@import url("modules/Share/style.css?v=1540399986");
@import url("modules/FileTaskMonitor/style.css?v=1540399970");
@import url("modules/BandwidthControl/style.css?v=1540399982");
@import url("modules/TrafficReport/style.css?v=1540400015");
@import url("modules/PollingTask/style.css?v=1540399986");
@import url("modules/WelcomeTip/style.css?v=1540399973");
@import url("modules/VideoPlayer2/style.css?v=1540400046");
@import url("modules/HelpBrowser/style.css?v=1540399986");
@import url("modules/SupportForm/style.css?v=1540399986");
@import url("modules/WelcomeApp/style.css?v=1540399973");
@import url("modules/ThumbConvertProgress/style.css?v=1540399982");
@import url("modules/PkgManApp/style.css?v=1540399986");
@import url("modules/Bodymovin/style.css?v=1540399986");
@import url("modules/ChartLib/style.css?v=1540399986");
@import url("modules/DSMNotify/style.css?v=1540399986");
@import url("modules/PersonalSettings/style.css?v=1540399986");
@import url("modules/Utils/style.css?v=1540399986");
@import url("modules/nsm-Wifi/style.css?v=1540399999");
@import url("modules/WelcomeInstaller/style.css?v=1540399973");
@import url("modules/MobileSetup/style.css?v=1540399973");
@import url("modules/SecurityScan/style.css?v=1540399983");
@import url("modules/AudioPlayer/style.css?v=1540399986");
@import url("modules/DataDrivenDocuments/style.css?v=1540399986");
@import url("modules/BackupReplicationApp/style.css?v=1540399998");
</style>
<style type="text/css">
@import url("modules/FileBrowser/style.css?v=1540399970");
</style>
<link rel="stylesheet" type="text/css" href="3rdparty/addon-azure_blob/style.css?v=1540400017" />
<link rel="stylesheet" type="text/css" href="3rdparty/addon-aws_s3/style.css?v=1540400083" />
<link rel="stylesheet" type="text/css" href="3rdparty/addon-sfr_s3/style.css?v=1540399968" />
<link rel="stylesheet" type="text/css" href="3rdparty/addon-hicloud_s3/style.css?v=1540400023" />
<link rel="stylesheet" type="text/css" href="3rdparty/SafeAccess/style.css?v=1537934111" />
</head>
<body>
<img id="sds-wallpaper" />
<!-- Don't contain any text node to avoid IE insertBefore bug -->
<div id="sds-login-dialog-form" style="position: absolute; top: -10000px; left: -10000px;"><form id="login-form" class="x-plain-body" method="POST" action="login.cgi" target="login_iframe" onsubmit="return true;"><input type="text" id="login_username" name="username" maxlength="256" /><input type="password" id="login_passwd" name="passwd" maxlength="256" /><input type="text" id="login_otp" name="OTPcode" maxlength="8" autocomplete="off" /><input type="submit" id="login_submit" style="position: absolute; top: -10000px; left: -10000px;" tabindex="-1" /></form><iframe id="login_iframe" name="login_iframe" width="0" height="0" frameborder="0" style="display: none;"></iframe></div>
<div id="sds-apply-preview-form" style="position: absolute; top: -10000px; left: -10000px;"><form id="preview-form" class="x-plain-body" method="POST" action="modules/ControlPanel/modules/dsm.cgi" target="preview_iframe" onsubmit="return true;"><input type="submit" id="preview_submit" style="position: absolute; top: -10000px; left: -10000px;" tabindex="-1" /></form><iframe id="preview_iframe" name="preview_iframe" width="0" height="0" frameborder="0" style="display: none;"></iframe></div>
<script type="text/javascript" src="synodefs.cgi?v=1540399973"></script>
<script type="text/javascript" src="/scripts/uistrings.cgi?lang=enu&v=1514770623"></script>
<script type="text/javascript" src="/webfm/webUI/uistrings.cgi?lang=enu&v=1514770623"></script>
<script type="text/javascript" src="uistrings.cgi?lang=enu&v=1514770623"></script>
<script type="text/javascript" src="/scripts/prototype-1.7.2/prototype.js?v=1540399953"></script>
<script type="text/javascript" src="/scripts/ext-3/adapter/ext/ext-base.js?v=1540399953"></script>
<script type="text/javascript" src="/scripts/ext-3/ext-all.js?v=1540399953"></script>
<script type="text/javascript" src="/scripts/ext-3/ux/ux-all.js?v=1540399953"></script>
<script type="text/javascript" src="/scripts/scrollbar/flexcroll.js?v=1540399953"></script>
<script type="text/javascript" src="/synoSDSjslib/sds.js?v=1540399966"></script>
<script type="text/javascript" src="desktop.js?v=1540399973"></script>
<script type="text/javascript">SYNO.SDS.Session = {
"configured" : true,
"diskless" : true,
"enable_syno_token" : "yes",
"fullversion" : "1514764831",
"hostname" : "SynologyRouter",
"isLogined" : false,
"lang" : "enu",
"login_background_color" : "#FFFFFF",
"login_background_enable" : false,
"login_background_ext" : ".jpg",
"login_background_hd_enable" : false,
"login_background_pos" : "center",
"login_background_seq" : 0,
"login_background_type" : "fromDS",
"login_enable_fp" : 0,
"login_logo_enable" : false,
"login_logo_ext" : ".jpg",
"login_logo_pos" : "center",
"login_logo_seq" : 0,
"login_only_bgcolor" : false,
"login_style" : "tpl1",
"login_version_logo" : true,
"version" : "1514764831"
}
;</script>
<script type="text/javascript"></script>
<div class="pre-load-x-window-br"></div>
</body>
</html>
答案 0 :(得分:0)
在给定的XPath中,您将使用id作为第一个参考点。我假设您也对cssSelector做过同样的事情。
由于这些ID是随机生成的,因此每次都不同。例如,给定的代码和XPath具有不同的ID。
尝试使用以下CSS选择器
CSS:
driver.find_elements_by_css_selector("div[ext:tree-node-id='SYNO.SDS.NSMWifi.Wireless.Main'] > a");
XPath:
driver.find_elements_by_xpath("//div[@ext:tree-node-id='SYNO.SDS.NSMWifi.Wireless.Main']/a");
如果无法选择弹出元素,则可能需要切换到活动元素。
答案 1 :(得分:-1)
如果未显示任何定位符,并且在同一窗口中生成了该定位符,则很可能会发出警报。 如果是警报,则只需尝试 driver.switchTo()。alert()。accept()或(您要执行的任何其他操作)。 希望对您有所帮助...
答案 2 :(得分:-1)
由于文本元素为无线的元素是JavaScript生成的元素,因此您需要为seccomp
引入 WebDriverWait ,您可以使用跟随Locator Strategy:
使用element_to_be_clickable()
:
XPATH
注意:您必须添加以下导入:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[@class='x-tree-node-icon nsm-wifi-icon-wireless']//following::a[1]/span[text()='Wireless']"))).click()