- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的一些 Selinium Webdriver 测试中,我注意到我无法通过调用 submit()
来提交表单。在表单的任何元素上,但我可以调用 click()
在提交按钮上就好了。我创建了一个简单的测试网页来说明问题。在下面的示例中,当我调用 submit()
时,我看到提交按钮。但是当我调用 click()
,表单实际上已提交,我看到“已提交”。
<html>
<body>
<?php if(isset($_POST["submit"])): ?>
Submitted
<?php else: ?>
<form method="post">
<input id="submit" name="submit" type="submit" value="submit">
</form>
<?php endif; ?>
</body>
</html>
我正在使用 this Selenium 模板,这是我的测试的样子:
@Listeners(ScreenshotListener.class)
public class LoginTest extends SeleniumBase {
@Test
public void test() {
WebDriver driver = getDriver();
driver.get("http://localhost/test.php");
WebElement submit = driver.findElement(By.id("submit"));
submit.click(); // works
// submit.submit(); // doesn't work
}
}
最佳答案
好的,所以,我有一个类似的问题,我想分享一个迄今为止一直为我服务的解决方案。在某些网页上,我必须使用 .Submit()
,而在某些网页上,我必须在按钮元素上使用 .Click()
。我必须在其上使用 .Click()
的页面会告诉我输入的用户名或密码不正确;尽管如此,如果我省略 .Submit()
部分并手动单击,它会使用以编程方式填写的凭据登录。所以,我必须通过它的 id 找到它的按钮元素,并在它上面使用 .Click()
。第二个网站的行为完全相反,当 .Click()
在按钮上使用时,它什么也不做。相反,.Submit()
有效。
所以,为了解决这个问题直到我弄清楚(我已经研究了一段时间),这就是我所做的。大多数网站在 Enter
键按下事件上执行提交,所以,这正是我所做的。
这是我的代码片段:
private void Login(string url, string usernameElement, string username,
string passwordElement, string password)
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(url);
IWebElement query = driver.FindElement(By.Id(usernameElement));
query.SendKeys(username);
query = driver.FindElement(By.Id(passwordElement));
query.SendKeys(password);
query.SendKeys(Keys.Enter); // simulates Enter key down to submit
}
这个小改动让我省去了很多麻烦。我已经在其他几个网站上对其进行了测试,到目前为止没有任何问题。我知道这不是库问题的完整修复,但它是A 修复。
关于php - Selenium click() 有效但 submit() 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20587449/
我创建了一个函数来在两个元素的 style.display 之间切换为“none”或“block”。我在这里遇到的问题是“发送”按钮似乎与“切换”按钮具有相同的行为。这不是我指定它要做的事情。我想知道
当我使用 validate.js 添加表单验证时,其验证正常并显示验证消息。但输入 type="submit"值在操作页面结构中显示两次。 为了说明,我有两个 .cfm 文件,index.cfm 具有
我有一个 s:form,里面有 sj:submit 和 s:submit,sj:submit 工作正常,但 s:submit 按钮不起作用。当我点击 s:submit 按钮时没有任何反应。 我尝试在表
参见http://jsfiddle.net/8KNc7/5/有关我正在讨论的内容的工作示例(目前在 Firefox 15 中进行测试,尚未尝试其他版本)。 我有一个带有 submit 输入和 butt
我有一个包含表单的 HTML 页面。我想做一些字段 "required" 。问题是我没有使用 在我的表单中,我使用 Javascript 函数来提交表单,因为我需要将 Javascript 变量发送到
如果用户提交表单,我想运行特定的 PHP block 。如果我使用带有 name="submit"的提交按钮并且: 我对 javascript 一无所知,我希望代码在用户更改下拉菜单时运行。如果我将
我有一个网站 www.abc.com,其中有一个页面 xyz.php。 xyz.php 采用表单提交事件读取数据并保存在数据库中。 www.abc.com 有一个针对 xyz.php 执行操作的表单。
这个问题在这里已经有了答案: JavaScript post request like a form submit (32 个答案) 关闭 9 年前。 我查看了不同的线程,但找不到合适的解决方案。
我有一个表单提交触发器和一个确认引导框,它显示在单击表单提交按钮上。在 bootbox 中确认如果用户同意我提交表单。我的问题是 onsubmit 在用户说是之前触发,并且当我在 bootbox 中调
我正在使用 JavaScript .submit() 函数提交我的表单。 form.submit(); 但是当我使用 addEventListener 来捕获我的提交事件时,它不起作用。 form.a
编辑:在考虑回答问题之前,请仔细阅读问题的所有内容。我既不是在生产代码中使用内联事件处理程序的可取性,也不是在实现我所引用的文章所 promise 的结果的最佳方法。这是关于Javascript语义和
这是我的形式,对我来说看起来不错。在这种形式中,我放置了这个按钮: 这是它调用的函数: function confirmSubmit() { // get the number of st
以下哪个 CSS 选择器更快? input[type="submit"] { /* styles */ } 或 [type="submit"] { /* styles */ } 只是好
在表单上添加提交按钮的符合标准的正确语义方式是什么?我不需要按钮中的图像或背景,只需要简单的文本,也许是带弯 Angular 的渐变背景(使用 CSS3)。这些是我所知道的方法: click her
我的 App.js 包含以下代码: var app = angular.module('githubApp', []); 我有 githubAppController 和以下代码: app.contr
jQuery 允许通过以下任一方式以编程方式触发表单提交: $('.js-form-class-hook').submit(); $('.js-form-class-hook').trigger('s
我有一个表单,其中一个按钮使用 onClick 事件提交。 " 此外,我有一个输入,当输入处于焦点状态时按下回车键时会触发 couponButton。 虽然它们都触发相同的事件 (.submit()
目前只是尝试实现这些按钮:http://web.archive.org/web/20110721191046/http://particletree.com/features/rediscoverin
我正在提交我的第一个构建以供 TestFlight beta 审查,在创建一个组后,添加 4 名团队成员添加我的构建,取消单击该框以表示我需要登录信息来测试该应用程序,我单击“提交”审查。” iTun
我有一个带有 onsubmit 属性的表单。我需要绑定(bind)一个新的提交事件,并且我需要在任何现有提交函数之前执行此事件。 下面的代码演示了这个问题。 Test
我是一名优秀的程序员,十分优秀!