[英]Selenium Firefox do not attach onClick event to submit button
我有一个带有如下所示的提交按钮的:
<input type="submit" class="btn btn-info pull-right save_button" id="save_button" value="Save"/>
使用JQuery,我将附加onclick事件以弹出确认框:
$('body').on("click", ".save_button", function() {
bootbox.confirm("Do you want these changes to be live in the website?",
function(result) {
if(result) {
$("#editPageForm").parsley().validate();
if( $("#editPageForm").parsley().isValid()) {
$("#editPageForm").submit();
}
}
});
return false;
});
当我手动测试此步骤时,一切正常,表单将通过验证并显示确认框,然后按OK按钮将其保存为预期的内容。
但是,如果我使用Selenium测试,则可以看到所有步骤都正常,但是当按下保存按钮而不是触发此功能时,只需提交表单即可。
这是用于创建驱动程序的代码:
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
return new FirefoxDriver(profile);
其他Javascript代码也可以使用,但是我遇到了与此特定的问题。
我正在使用FF44和硒驱动程序,我尝试了2.48.2、2.49.1、2.50,但都没有用
你们有没有遇到过类似的问题?
谢谢
可能是因为页面尚未完全呈现,因此尚未注册点击侦听器。 添加等待可以解决您的问题,例如:
WebDriverWait buttonWait = new WebDriverWait(driver, 30L);
buttonWait.until(ExpectedConditions.visibilityOfElementLocated(By.id("someButton")));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.