[英]Playwright Java : Playwright fails to click on element whose property is set hidden
也许使用 click 方法的 force 选项会帮助你:
page.locator("some_selector").click( {force: true} );
try dispatchEvent尝试调度事件
Regardless of the visibility state of the element, click is dispatched.无论元素的可见性状态如何,都会调度单击。 This is equivalent to calling element.click()
.这相当于调用element.click()
。
await element.dispatchEvent('click');
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 eg a class or an attribute, or try and force the click using the DOM which is probably a better way to do it.它有点肮脏的方式,但你可以更改 CSS 如果那里有东西使它隐藏,例如 class 或属性,或者尝试使用 DOM 强制点击,这可能是更好的方法.
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();");
Good luck and let me know how it goes.祝你好运,让我知道情况如何。 Sorry if my syntax is a little off.对不起,如果我的语法有点不对劲。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.