Rayrun
← Back to Discord Forum

How to toggle the visibility of an element ?

tenacious_beagle_27655posted in #help-playwright
Open in Discord
tenacious_beagle_27655

How cam I toggle the visibility of an element. I was trying to use the code below, but it does not work

` var element = document.getElementsById('test');

element].style.display = 'none';`

This thread is trying to answer question "How can I toggle the visibility of an element using JavaScript?"

4 replies

You can execute JavaScript in the browser using page.evaluate()

Reference: https://playwright.dev/docs/evaluating

await page.evaluate(async () => {
  const element = document.getElementById('test');
  element.style.display = 'none';
});

I'm confused PW should be used to test an application not drive and alter the web page... How would a user make the element in the application toggle the visibility. Unless your users will actually need to toggle the visibility by executing javascript, seems like the tail wagging the dog...

Can't count how many times i've seen bugs in and app get shipped by doing this...

tenacious_beagle_27655
@shivaguy: Thank you so much @shivaguy

Thank you so much @shivaguy

tenacious_beagle_27655
@dand33: I want to toogle the visibility for an element that is not going to be present in production application.

I want to toogle the visibility for an element that is not going to be present in production application.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.