- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚更新到 Protractor 2.0,我发现我的项目中存在一些问题。
expect()
失败,因为给定的文本是 ''
似乎 expect 在 sendKeys()
完成之前完成。
elem.clear().sendKeys('Message');
expect(elem.getAttribute('value')).toBe('Message');
我得到的错误是:
Expected '' to be 'Message'.
这在更新到 Protractor 2.0 之前有效,而且我知道 beaking changes is related with then() and promises 中的一个:
To enable the update and remove confusion, this removes the element().then function unless there is an action result. This function is completely unnecessary, because it would always resolve to itself, but the removal may cause breaking changes. In other words, an ElementFinder is now no longer a promise until an action has been called.
但在我的项目的其他测试中它起作用了,我认为问题可能与我在循环中执行 expect 相关。这里是完整的代码
describe('message', function() {
it('Should fill out visible message fields', function(){
getDisplayedElements(element.all(by.model('message')))
.then(function(displayedMessageInputs){
_.each(displayedMessageInputs, function(elem){
elem.clear().sendKeys('Message');
expect(elem.getAttribute('value')).toBe('Message');
});
});
});
});
如果我使用 then() 函数,它可以工作,但是......我不喜欢它!
elem.clear().sendKeys('Message')
.then(function(){
return elem.getAttribute('value');
})
.then(function(inputValue){
expect(inputValue).toBe('Message');
});
最佳答案
您展示的第二种方法是正确的方法。 Promises 用于清楚地组织异步回调行为。除非 Promise 在您预期之前解决,否则无法捕获 sendKeys 异步回调。此外,看起来它实际上返回了一个 Promise,在这种情况下,使用函数提供的内容似乎是明智的。如果你不喜欢使用两个 then,你总是可以期待:
elem.clear().sendKeys('Message')
.then(function(){
expect(elem.getAttribute('value')).toBe('Message');
});
关于javascript - Protractor 2.0 不等待 sendKeys() 。 promise 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29697836/
其使用格式为: object.SendKeys string "object":表示WshShell对象 "string":表示要发送的按键指令字符串,需要放
如何使用命令 sendKeys(Keys.TAB) 和 sendKeys("text") 填写列中的几个字段。例如:页面底部的“联系我们”表单中有 3 个字段: 姓名 电子邮件 留言和“提交”按钮。
sendkeys(keys.Down) 和 sendkeys(keys.Arrow_Down) 之间有什么区别在 Selenium java中 最佳答案 没有区别,在以前版本的 selenium 中,
我的测试是在搜索文本框中输入键(主要是ajax),然后按键盘上的回车键。没有“开始”搜索的按钮,因此我们使用 Enter 键。 我使用 ChromeDriver,因为我们的应用程序在此流程中不支持 F
我试图在 sendKeys 方法 [type WebElement] 中将“String”作为参数发送,但系统将其用作 char 序列,所以我没有得到正确的输出。 public static
我想在新窗口中打开应用程序的链接。使用操作类在我当前所在的同一窗口中打开链接。 我尝试在多个应用程序的 Chrome 驱动程序和 Firefox 驱动程序上使用带有以下代码的 Actions 类,但没
据我所知,有两种使用 Selenium 进行输入的方法: new Actions(webDriver).sendKeys("text to send").perform(); webElement.s
我正在使用 Selenium 通过 VS Code 用 Java 进行编写。 我无法编译这行代码,因为 sendKeys 方法下有一条红线。 代码行是: driver.findElement(By
我正在使用以下过程作为 OnTime 方法的一部分: Public Sub Countdown() ThisWorkbook.Activate SendKeys ("{ESC}")
我是 VBA 的新手,我的研究表明我不应该使用 .SendKeys,因为它不可靠。我应该为以下使用什么替代代码? Application.SendKeys ("{Home}") 最佳答案 这看起来选择
我正在使用 .SendKeys()在 Excel VBA 中将击键发送到我正在使用 shell .AppActive 激活的外部窗口方法。问题是 SendKeys只是行为不一致,有时发送 key ,有
我正在使用 (new Actions(driver).sendKeys(String).perform() 将输入发送到 webdriver。但是,我一直得到不一致的结果。有时 String 会完美发
我用 Java 编写了脚本,它正在 Chrome 浏览器中运行。我有一个用户名字段、密码字段和一个登录按钮。甚至在完成用户名字段中的输入之前,它就开始在密码字段/登录按钮上执行操作。 这是我的代码,
我使用 sendkey 访问 Power Query 并连接到 SharePoint 文件夹。一切都很顺利,直到出现 Power Query 数据预览对话框。 如何允许 sendkey 在对话框出现后
我在输入一些特殊字符时遇到了一些问题 SendKey.Send("~!@#$%^&*()_+|") . 当我尝试输入 ~!@#$%^&*()_+| 时, 只有 !@#$*_|已输入。 有办法解决这个问
我创建了一个键盘应用程序,它保持在顶部,但不获取焦点,因此在触摸屏上它会通过 SendKeys 将您按下的任何键转发到事件应用程序。 它与我尝试过的每个应用程序都完美配合……当然,除了我实际需要它使用
我正在尝试使用 sendkeys,但将它发送到一个非焦点程序。例如,我想使用 sendkeys 到 Notepad - Untitled,但它没有被聚焦。抱歉,如果不清楚,我会详细说明。我当前的代码是
我希望我的 C# 程序在继续之前关闭某个遗留应用程序。使用 ctrl+x 可以立即关闭旧版应用程序。我可以使用 Sendkeys 来做到这一点,但我听说 sendkeys 可能有点不稳定。有没有其他方
您好,我已经在 login-page.js 中编写了这段代码 我不知道为什么会出现错误 失败:无法读取未定义的属性“sendKeys” 我在 login_spec.js 上调用了这个页面 我无法在 P
我在表单中有两个输入字段,它们的来源在下面提到 我正在尝试在 selenium 网络驱动程序 (Firefox) 中使用以下命令发送输入 driver.findElement(By.cssSele
我是一名优秀的程序员,十分优秀!