网页对JavaScript .click()的响应不同,而不是普通的鼠标单击

发布于 2025-02-02 17:06:25 字数 380 浏览 5 评论 0原文

当我使用.click()事件的多个不同变体上单击网页上的特定元素时取消:troo,查看:window}})); 或 document.queryselectorall(selector)[pos] .click()该网页未正确加载相应的页面;实际上,其中一些事件过去几天前工作了,但是现在不再工作了,即使我使用JavaScript发送重新加载请求到页面上,也不会显示预期的动态元素和响应式代码。相反,它只是在我期望信息的情况下显示一个空白的结果。它要求我使用自己的鼠标发送手动点击事件,然后单击重新加载以重新出现的相应动态代码。

是否有一种方法可以使用JavaScript正确并完全模拟鼠标单击,使其与普通点击是无法区分的?我已经尝试了一些Mouseevents,但也许我只是将它们配置为错误,或者网页对执行控制台的命令的响应不同。

When I click on a particular element on a webpage using multiple different variants of the .click() event e.g. document.querySelectorAll(selector)[pos].dispatchEvent(new MouseEvent('click', {{ bubbles: true, cancelable: true, view: window }})); or document.querySelectorAll(selector)[pos].click() the webpage doesn't load the corresponding page properly; in fact, some of these events used to work a few days ago but now don't work anymore and even if I send a reload request using javascript to the page, it doesn't show the expected dynamic elements and responsive code. Instead, it just shows a blank result where I expected information. It requires me sending a manual click event using my own mouse and clicking on the reload for the corresponding dynamic code to reappear.

Is there a way to properly and fully simulate a mouse click using javascript such that it is indistinguishable from a normal click? I've tried a few MouseEvents but perhaps I'm just configuring them wrong, or the webpage is responding differently to console executed commands.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝天白云 2025-02-09 17:06:25

我发现了一种系统地单击网站元素的方法,这在很大程度上是不可思议的。基本上使用pyppeteer使用document.queryselectorall(*元素类名称*)[*position*]。getBoundingClientRect()

使用pyautogui单击该元素,我发现使用此方法的工作良好,请单击该元素,

def safeClick(baseX,baseY):
    pyautogui.moveTo(baseX,baseY,1+random.random())
    step=random.randrange(1,7)
    for i in range(step):
        baseX=baseX+random.random()
        pyautogui.moveTo(baseX,baseY)
    pyautogui.mouseDown(baseX,baseY)
    time.sleep(random.random())
    pyautogui.mouseUp(baseX,baseY)

Remember that in most browsers the getBoundingClientRect() coordinates are not exactly the same as the pyautogui coordinates, you'll need to use my answer here

编辑:请注意,此答案在Python中有效,如果您要使用JavaScript,我很确定这是不可能的

I found a method of systematically clicking website elements largely untraceably. Basically use pyppeteer to locate the chosen element using document.querySelectorAll(*element class name*)[*position*].getBoundingClientRect()

Then click the element using pyautogui, I found using this method worked pretty well

def safeClick(baseX,baseY):
    pyautogui.moveTo(baseX,baseY,1+random.random())
    step=random.randrange(1,7)
    for i in range(step):
        baseX=baseX+random.random()
        pyautogui.moveTo(baseX,baseY)
    pyautogui.mouseDown(baseX,baseY)
    time.sleep(random.random())
    pyautogui.mouseUp(baseX,baseY)

Remember that in most browsers the getBoundingClientRect() coordinates are not exactly the same as the pyautogui coordinates, you'll need to use my answer here how to find offsets in any browser configuration.

EDIT: Note this answer works in python, if you're trying to use javascript I'm pretty sure it's largely impossible

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文