我正在尝试与按钮进行互动。 Selenium / Nightwatch.js找不到。
该按钮不在其他iframe中。 我尝试了多个选择器,但没有一个工作 元素不会被隐藏,可以手动点击。 此外,我还尝试添加等待,以确保它不是时间问题。
我可以验证身体的存在,之后硒没有其他元素可见。
我的代码:
.pause(5000)
.useCss()
.verify.visible('.coral-MinimalButton.toggle-sidepanel.editor-GlobalBar-item.js-editor-SidePanel-toggle')
.verify.visible('html.wf-adobeclean-i4-active.wf-adobeclean-n3-active.wf-adobeclean-n4-active.wf-adobeclean-n7-active.wf-adobecleancondensed-n4-active.wf-adobecleancondensed-n7-active.wf-active body.coral--light div#Content.editor-panel.editor-panel-active div.editor-GlobalBar.js-editor-PanelHeader.editor-panel-header nav.coral-Panel-header.coral-GlobalBar-main.header-main div.editor-GlobalBar-leftContainer button.coral-MinimalButton.toggle-sidepanel.editor-GlobalBar-item.js-editor-SidePanel-toggle')
.click('.coral-MinimalButton.toggle-sidepanel.editor-GlobalBar-item.js-editor-SidePanel-toggle')
.click('html.wf-adobeclean-i4-active.wf-adobeclean-n3-active.wf-adobeclean-n4-active.wf-adobeclean-n7-active.wf-adobecleancondensed-n4-active.wf-adobecleancondensed-n7-active.wf-active body.coral--light div#Content.editor-panel.editor-panel-active div.editor-GlobalBar.js-editor-PanelHeader.editor-panel-header nav.coral-Panel-header.coral-GlobalBar-main.header-main div.editor-GlobalBar-leftContainer button.coral-MinimalButton.toggle-sidepanel.editor-GlobalBar-item.js-editor-SidePanel-toggle')
.useXpath()
.verify.visible('//html/body/div[4]/div[1]/nav/div[1]/button[1]')
.click('//html/body/div[4]/div[1]/nav/div[1]/button[1]')
// again pointing to the same element now using partial css
.useCss()
.verify.visible('button[title="Toggle Side Panel"]')
.click('button[title="Toggle Side Panel"]')
// Trying to verify the body is locatable
.verify.visible('body[class="coral--light"]')
// This verifies I can locate the body
.verify.visible('html.wf-adobeclean-i4-active.wf-adobeclean-n3-active.wf-adobeclean-n4-active.wf-adobeclean-n7-active.wf-adobecleancondensed-n4-active.wf-adobecleancondensed-n7-active.wf-active body.coral--light')

<body class="coral--light">
<div class="foundation-authoring-ui-mode hidden" data-classic-editor-
url="/cf#"></div>
<div class="foundation-content-path hidden" data-foundation-content-
path="/content/citypages/en/test3.html"></div>
<div id="SidePanel" class="sidepanel sidepanel-closed">
<div class="sidepanel-header editor-GlobalBar">
<nav class="toolbar" data-init="toolbar">
<div class="left icongroup">
<span class="sidepanel-header-title sidepanel-header-title-assetfinder"
title="Search Assets" style="display: none;">Search Assets</span>
<span class="sidepanel-header-title sidepanel-header-title-components"
title="Components" style="display: inline;">Components</span>
</div>
<div class="right icongroup">
</nav>
</div>
<div class="sidepanel-content sidepanel-content-with-header">
<div class="sidepanel-resizer"></div>
</div>
<div id="Content" class="editor-panel editor-panel-active">
<div class="editor-GlobalBar js-editor-PanelHeader editor-panel-header">
<nav class="coral-Panel-header coral-GlobalBar-main header-main">
<div class="editor-GlobalBar-leftContainer">
<button class="coral-MinimalButton toggle-sidepanel editor-GlobalBar-item js-
editor-SidePanel-toggle" data-align="left" data-iconsize="S" title="Toggle
Side Panel" autocomplete="off" type="button">
&#13;
最后一个按钮就是那个。尝试找到元素需要做什么?
答案 0 :(得分:0)
您可以在xpath下面尝试: -
CҴPSRдϴ5^Cδ^T�-�ڴ^S�۴m�۴m�۴m�۴mT�-�ڴM�:��۴-��-�״^[m���۴]m�۶۶m�Ǫ�\�m�rN^RՅ
答案 1 :(得分:0)
这个选择器比需要的更冗长,但我这样做了,所以你可以看到它如何遍历页面到达那里。当我在上面的代码上运行它时它可以工作。
driver.FindElement(By.CssSelector("body.coral--light div#Content button[type=button]")
如果这不起作用,页面上还会有其他影响元素可见性的内容。如果页面是公开的,请发送URL,我会看看。
答案 2 :(得分:0)
这是在javascript中更改窗口的解决方案,我关闭了第一个然后切换到第二个。感谢大家的时间和考虑。
.closeWindow()
.pause(1000)
.window_handles(function(result) {
var newHandle = result.value[0];
this.switchWindow(newHandle);
})