我目前正在尝试为我公司的grails应用程序进行自动化测试。我在javascript中使用selenium。问题是我需要检查是否生成了包含值的表单,但每当我尝试检查该值时,它都会给我一个很长的错误。这是应该起作用的代码:
console.log(
driver.findElement(
By.xpath("//*[@id='manual-order-mail-from-name']")
).getAttribute("value")
);
我想要的元素在这里:
<input
type="text"
class="form-control input-sm mail-from-input valid"
name="mailFromName"
id="manual-order-mail-from-name"
placeholder="Name"
required=""
aria-required="true"
aria-invalid="false">
以下是错误消息:
ManagedPromise {
flow_:
ControlFlow {
propagateUnhandledRejections_: true,
activeQueue_:
TaskQueue {
name_: 'TaskQueue::709',
flow_: [Circular],
tasks_: [Object],
interrupts_: null,
pending_: null,
subQ_: null,
state_: 'new',
unhandledRejections_: Set {} },
taskQueues_: Set { [Object] },
shutdownTask_: null,
hold_:
Timeout {
_called: false,
_idleTimeout: 2147483647,
_idlePrev: [Object],
_idleNext: [Object],
_idleStart: 461,
_onTimeout: [Function],
_timerArgs: undefined,
_repeat: 2147483647 } },
stack_:
{ Task: WebElement.getAttribute(value)
at thenableWebDriverProxy.schedule (/Users/takeshi/WebstormProjects/Regression/node_modules/selenium-webdriver/lib/webdriver.js:816:17)
at WebElementPromise.schedule_ (/Users/takeshi/WebstormProjects/Regression/node_modules/selenium-webdriver/lib/webdriver.js:1921:25)
at WebElementPromise.getAttribute (/Users/takeshi/WebstormProjects/Regression/node_modules/selenium-webdriver/lib/webdriver.js:2171:17)
at /Users/takeshi/WebstormProjects/Regression/TEST-11.js:43:92
at ManagedPromise.invokeCallback_ (/Users/takeshi/WebstormProjects/Regression/node_modules/selenium-webdriver/lib/promise.js:1384:14)
at TaskQueue.execute_ (/Users/takeshi/WebstormProjects/Regression/node_modules/selenium-webdriver/lib/promise.js:3092:14)
at TaskQueue.executeNext_ (/Users/takeshi/WebstormProjects/Regression/node_modules/selenium-webdriver/lib/promise.js:3075:27)
at asyncRun (/Users/takeshi/WebstormProjects/Regression/node_modules/selenium-webdriver/lib/promise.js:2935:27)
at /Users/takeshi/WebstormProjects/Regression/node_modules/selenium-webdriver/lib/promise.js:676:7
at process._tickCallback (internal/process/next_tick.js:103:7) name: 'Task' },
parent_: null,
callbacks_: null,
state_: 'pending',
handled_: false,
value_: undefined,
queue_: null }
它是用户点击按钮时显示的模式的一部分。我的猜测是,这与它有关,但我不知道。
我已经搜遍了所有人,似乎无法找到解决方案。如果您对此有任何见解,请告诉我。
答案 0 :(得分:0)
事实证明我对getAttribute返回的内容有不正确的理解。它实际上返回一个你需要捕获然后输出的承诺。像这样:
driver.findElement(By.xpath("//*[@id='manual-order-mail-from-name']")).getAttribute("value").then(function (success) {console.log("this is the text" + success);}, function(e) {console.log("this was the error" + e);});