-1

I tried many locators but looks like its hidden so playwright fails to click any workaround please help

Blockquote

sumit goyal
  • 35
  • 1
  • 7
  • 2
    [Please don't post code, exceptions, or results as images](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question). They can't be copied (partly) for answering and their "text" won't appear in search engines. – Gert Arnold Jun 04 '22 at 20:24
  • please add your whole code which we can copy and run. – MeT Jun 10 '22 at 23:26

3 Answers3

1

Maybe using force option of click method will help you:

page.locator("some_selector").click( {force: true} );
1

Its a bit of a dirty way to do it but you can change the CSS if there is something there that makes it hidden e.g. a class or an attribute, or try and force the click using the DOM which is probably a better way to do it.

Locator locator = page.locator("YOUR LOCATOR HERE");
locator.evaluate("node => node.classList.remove('classToRemove');");
//I cannot stress enough that this is a last resort as it can be a bit flakey

//or you could try this which might be a better option for your
Locator locator = page.locator("YOUR LOCATOR HERE");
locator.evaluate("node => node.click();");
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Lilpercy11
  • 86
  • 3
0

try dispatchEvent

Regardless of the visibility state of the element, click is dispatched. This is equivalent to calling element.click().

await element.dispatchEvent('click');
rootShiv
  • 1,375
  • 2
  • 6
  • 21