刚刚开始使用 selenium,这是页面的 HTML:
<div id="signInForm">
<form action="/cgi-bin/VmLoginCgi" method="POST" name="signIn1" id="signIn">
<h2 id="loginTitle">Sign in to view and change your settings</h2>
<div class="field formField noHint username clearfix">
<label for="username"></label>
</div>
<div style="position:relative;" class="field formField noHint password clearfix"><label for="password">Settings Password</label><input type="password" autocomplete="off" value="" maxlength="15" class="name required onefiftyPX inactive" name="jgwhnZLOXn" id="password" onkeypress="handleKeyPress(event)"></div>
<div>
<a href="javascript:SignIn()" class="newCta ctaLarge ctaPrimaryLarge floatLeft">Sign In</a>
</div>
</form>
<p>
<span style="font-weight:bold;">Don't know your password?</span><br>You'll find your default password on the bottom of your Super Hub.
</p>
</div>
我正在通过以下方式填写文本框:
ele = browser.find_element_by_id("password")
ele.send_keys("supersecretpassword")
但无法通过执行 javascript 提交实际表单。我尝试过:
browser.execute_script("SignIn()")
但是出现了一个很长的错误,有什么指示吗?
最佳答案
使用submit()
提交表单:
ele.submit()
它将找到该元素的父表单并提交它。
或者,如果这不适用于您的情况,请找到登录
按钮并单击它:
driver.find_element_by_link_text("Sign In").click()
关于python - 如何使用selenium填写表单后执行javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31842646/