简体   繁体   中英

Selenium Multiple Selectors can't locate elements

I am trying to interact with a button. Selenium/Nightwatch.js can not locate.

The button is not within a different 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.

This was the solution for changing windows in javascript, I closed the first then switched to the second. Thanks to everyone for your time and consideration.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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