OnetapInc / chromy

Chromy is a library for operating headless chrome. 🍺🍺🍺
MIT License
605 stars 41 forks source link

Hide elements in dom. #115

Open alucardu opened 6 years ago

alucardu commented 6 years ago

I have certain elements I don't want to show on my screenshots. Any way to hide them using Chromy?

dotneet commented 6 years ago

it is way to do that.

.evaluate(_ => {
  document.querySelector('#target').style.opacity = '0'
})
alucardu commented 6 years ago

That returns a

COMMAND | ReferenceError: document is not defined

Code--

var elementExists = document.getElementsByClassName(".searchbarX div .hidden-lower-xl");

chromy
  .wait(2500)
  .goto(scenario.url)

if (elementExists) {
  chromy
    .evaluate(_ => {
      document.querySelector('.searchbarX div .hidden-lower-xl').style.opacity = '0'
    })
}

It looks like it executes the code before the page is loaded.

dotneet commented 6 years ago

document can be accessed in evaluate context only.

does this works?

chromy
  .wait(2500)
  .goto(scenario.url)
  .evaluate(_ => {
      var elementExists = document.getElementsByClassName(".searchbarX div .hidden-lower-xl");
      if (elementExists) {
        document.querySelector('.searchbarX div .hidden-lower-xl').style.opacity = '0'
      }
    })
  .end()