简体   繁体   English

硒多个选择器无法找到元素

[英]Selenium Multiple Selectors can't locate elements

I am trying to interact with a button. 我正在尝试与按钮互动。 Selenium/Nightwatch.js can not locate. Selenium / Nightwatch.js找不到。

The button is not within a different iframe. 该按钮不在其他iframe中。 I have tried multiple selectors, none of them working. 我尝试了多个选择器,但没有一个起作用。
The elements are not hidden and can be clicked upon manually. 元素不是隐藏的,可以手动单击。 Also I have tried adding waits, in-order to ensure it is not a timing issue. 我也尝试添加等待,以确保它不是时间问题。

I can verify the existence of the body, after-which no other elements are visible to selenium. 我可以验证身体的存在,之后硒没有其他元素可见。

My Code: 我的代码:

 .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"> 

The last button is the one. 最后一个按钮是那个。 What do I need to do to try to locate the element? 我该怎么做才能找到该元素?

您可以在xpath下尝试:

//button[@title='Toggle Side Panel']

This selector is way more verbose than needed, but I did it this way so you can see how it traverses the page to get there. 这个选择器比需要的更为冗长,但是我这样做是为了让您看到它如何遍历页面到达那里。 It works when I run it on the above code. 当我在上面的代码上运行它时,它可以工作。

driver.FindElement(By.CssSelector("body.coral--light div#Content button[type=button]")

If that doesn't work, there is something else about the page that is affecting the element visibility. 如果这不起作用,则页面上还有其他因素会影响元素的可见性。 If the page is public send the URL and I'll take a look. 如果该页面是公开页面,请发送URL,然后我看一下。

This was the solution for changing windows in javascript, I closed the first then switched to the second. 这是在javascript中更改窗口的解决方案,我关闭了第一个然后切换到了第二个。 Thanks to everyone for your time and consideration. 感谢大家的时间和考虑。

  .closeWindow()
  .pause(1000)
  .window_handles(function(result) {
      var newHandle = result.value[0];
      this.switchWindow(newHandle);
        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM