我创建了一个用户脚本,该脚本从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();
Vanilla 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();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句