Javascript 如何通过GM userscript登录到neopets.com
我创建了一个userscript,它从Neopets开始,并自动填充用户名和密码。我无法让脚本单击巨大的绿色“登录”按钮Javascript 如何通过GM userscript登录到neopets.com,javascript,jquery,greasemonkey-4,Javascript,Jquery,Greasemonkey 4,我创建了一个userscript,它从Neopets开始,并自动填充用户名和密码。我无法让脚本单击巨大的绿色“登录”按钮 $('input[name=username']).val('username_here'); $('input[name=password']).val('password_here'); 我尝试了以下所有方法来单击登录按钮或提交表单 //这些都没有单击登录按钮: $(“input.submit[name='welcomeLoginButton'])。submit();
$('input[name=username']).val('username_here');
$('input[name=password']).val('password_here');
我尝试了以下所有方法来单击登录按钮或提交表单
//这些都没有单击登录按钮:
$(“input.submit[name='welcomeLoginButton'])。submit();
$(“input.submit[name='welcomeLoginButton'])。单击();
$('body')。在('click','welcomeLoginButton',function(){alert('logged in?');})上;
新建WebDriverWait(驱动程序,10).until(ExpectedConditions.ElementToBickable(By.cssSelector(“input.submit[name='welcomeLoginButton'])))。单击();
我知道没有名为“welcomeLoginButton”的元素,只有名为
.welcomeLoginButton
的类。填写用户名和密码后,如何让表单提交?只需使用类“welcomeLoginButton”获取所有元素的列表,然后单击第0个索引即可
jQuery版本:
$('.welcomeLoginButton')[0]。单击();
香草JS版本:
document.getElementsByClassName(“welcomeLoginButton”)[0]。单击();
//不带All的querySelector只返回数组的第一个索引
document.querySelector('.welcomeLoginButton')。单击();
document.querySelectorAll('.welcomeLoginButton')[0]。单击();
只需获取类的所有元素列表welcomeLoginButton
,然后单击第0个索引
jQuery版本:
$('.welcomeLoginButton')[0]。单击();
香草JS版本:
document.getElementsByClassName(“welcomeLoginButton”)[0]。单击();
//不带All的querySelector只返回数组的第一个索引
document.querySelector('.welcomeLoginButton')。单击();
document.querySelectorAll('.welcomeLoginButton')[0]。单击();
document.getElementsByClassName(“welcomeLoginButton”)[0]有什么问题。单击()?(.click()
不仅仅是一个jQuery功能)编辑:您也可以使用$('.welcomeLoginButton')[0]。click()
@Samathingamajig非常感谢,这两个功能都很有效!您可以将其作为答案发布吗?document.getElementsByClassName(“welcomeLoginButton”)[0]有什么问题吗?单击()?(.click()
不仅仅是一个jQuery功能)编辑:您也可以使用$('.welcomeLoginButton')[0]。click()
@Samathingamajig非常感谢,这两个功能都很有效!你能把这个作为答案吗?