javascript - 如何通过 GM 用户脚本登录 neopets.com
问题描述
我创建了一个从 Neopets登录页面开始并自动填充用户名和密码的用户脚本。我无法让脚本单击巨大的绿色“登录”按钮。
$('input[name=username']).val('username_here');
$('input[name=password']).val('password_here');
我已经尝试了以下所有方法来单击登录按钮或提交表单。
//None of these clicked the sign in button:
$("input.submit[name = 'welcomeLoginButton']").submit();
$("input.submit[name = 'welcomeLoginButton']").click();
$('body').on('click','welcomeLoginButton',function(){alert('logged in?');});
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.submit[name = 'welcomeLoginButton']"))).click();
我知道没有名为“welcomeLoginButton”的元素,只有一个名为.welcomeLoginButton
. 填写用户名和密码后,如何让表单自行提交?
解决方案
只需获取该类的所有元素的列表,welcomeLoginButton
然后单击第 0 个索引。
jQuery版本:
$('.welcomeLoginButton')[0].click();
香草 JS 版本:
document.getElementsByClassName("welcomeLoginButton")[0].click();
// querySelector without the All just returns the first index of the array
document.querySelector('.welcomeLoginButton').click();
document.querySelectorAll('.welcomeLoginButton')[0].click();
推荐阅读
- apache-kafka - 覆盖 Kafka MirrorMaker2 中的默认属性
- java - 当在声明中指定属性值更简单时,为什么还要在构造函数中指定属性值?
- r - 返回两个或多个最大相等值
- r - 在语音引号内调用本地人
- c# - 无法访问内存缓存 - ASP.NET Core
- kotlin - 即使我不使用模式生成,我是否应该在 Jetbrain 的 Exposed 上定义约束?
- bash - 从函数的输出创建 Bash 关联数组:为什么“declare -A foo=$(bar)”有效,但“declare -A foo; foo=$(bar)”无效?
- kotlin - 乐观锁定:不支持的版本类型长
- intellij-idea - IntelliJ Idea - 转到文件 > 为什么必须按 Ctrl+Enter 才能打开找到的文件?
- jsp - 如何使用零填充和区域设置小数分隔符格式化此数字?