首页 > 解决方案 > 如何在 LinkedIn 中模拟搜索?

问题描述

我正在尝试在 Javascript 控制台中模拟 Linkedin.com 中的搜索(我需要在 Javascript 中进行,以进行 chrome 扩展开发......而不是在 Phantom、Selenium 或其他浏览器模拟环境中)。

如果我这样做:

document.querySelector(".search-global-typeahead__input").dispatchEvent(new Event('focus', { bubbles: true }))

看起来它就像光标在它上面一样发生了变化(因为它触发了 CSS 行为和字段增长中的某些东西)。

但我无法在输入字段中输入内容。我的尝试:

document.querySelector(".search-global-typeahead__input").dispatchEvent(new KeyboardEvent('keypress',{'key':'a'}));
document.querySelector(".search-global-typeahead__input").dispatchEvent(new KeyboardEvent('keydown',{'key':'a'}));
document.querySelector(".search-global-typeahead__input").dispatchEvent(new Event('change'));
document.querySelector(".search-global-typeahead__input").dispatchEvent(new Event('click'));
...

我可以使用一个简单的“价值”:

document.querySelector(".search-global-typeahead__input").value = "Peter"

但是我怎样才能触发搜索呢?我试过keydowns和其他......

任何想法?

标签: javascriptgoogle-chrome-extensiondom-eventslinkedin

解决方案


推荐阅读