如何使用CasperJS填写AngularJS输入字段,不带表格标签(How to use CasperJS to fill in AngularJS input fields w/out a form tag)
我试图编写一个CasperJS脚本,它在https://frontier.com/login上进行登录。
我遇到了麻烦,因为:
它使用AngularJS,所以看起来我无法访问和更改其范围内的值(例如,
ng-model='login.loginId'
)。 直接在元素上设置值没有任何作用。输入字段不包含表单元素,所以使用通常的
fillSelectors()
和CasperJS是不可能的
casper.exists('input#fid-login-inline-username')
返回true,但是,casper.sendKeys('input#fid-login-inline-username', 'blah')
给出错误,说[error] [remote] mouseEvent(): Couldn't find any element matching 'input#fid-login-inline-username' selector
与之一起工作的领域是:
input#fid-login-inline-username
input#fid-login-inline-password
div.login-form-container button.btn-primary
- 用于click()
那么,如何将casper中的两个输入字段编辑为角度范围?
这是我尝试过的一个例子:
casper.start('https://frontier.com/login', function() { this.echo('waiting for password input field'); this.waitForSelector("input#fid-login-inline-password"); }); casper.then(function() { if (this.exists('input#fid-login-inline-username')) { this.echo('username input exists'); } if (this.exists('input#fid-login-inline-password')) { this.echo('password input exists'); } this.echo('filling in username and password'); // these fields are not in a form element, so, use sendKeys to enter text... // the above echoes print the fields exist, and then these sendKeys // operations emit an error that the fields don't exist. this.sendKeys('input#fid-login-inline-username', 'some@email.com'); this.sendKeys('input#fid-login-inline-password', 'some-password'); }); casper.then(function() { this.echo('clicking login button'); this.click('div.login-form-container button.btn-primary'); });
I'm trying to write a CasperJS script which does a login at https://frontier.com/login.
I'm having trouble because:
it uses AngularJS so it seems I can't access and change the values held in its scope (eg.
ng-model='login.loginId'
). Setting the values directly on the elements doesn't have any effect.the input fields are not wrapped with a form element so using the usual
fillSelectors()
with CasperJS isn't possible
casper.exists('input#fid-login-inline-username')
returns true, but,casper.sendKeys('input#fid-login-inline-username', 'blah')
gives an error saying[error] [remote] mouseEvent(): Couldn't find any element matching 'input#fid-login-inline-username' selector
The fields to work with are:
input#fid-login-inline-username
input#fid-login-inline-password
div.login-form-container button.btn-primary
- forclick()
So, how do I edit the two input fields from casper into the angular scope?
Here is an example of what I've tried:
casper.start('https://frontier.com/login', function() { this.echo('waiting for password input field'); this.waitForSelector("input#fid-login-inline-password"); }); casper.then(function() { if (this.exists('input#fid-login-inline-username')) { this.echo('username input exists'); } if (this.exists('input#fid-login-inline-password')) { this.echo('password input exists'); } this.echo('filling in username and password'); // these fields are not in a form element, so, use sendKeys to enter text... // the above echoes print the fields exist, and then these sendKeys // operations emit an error that the fields don't exist. this.sendKeys('input#fid-login-inline-username', 'some@email.com'); this.sendKeys('input#fid-login-inline-password', 'some-password'); }); casper.then(function() { this.echo('clicking login button'); this.click('div.login-form-container button.btn-primary'); });
原文:https://stackoverflow.com/questions/41626029
最满意答案
EDITED
create class Puntua extends E create class Sitio extends V create class Persona extends V create vertex Persona set name = 'person' # returns #17:0 create vertex Sitio set place = 'mcdonals' # returns #16:0 create vertex Sitio set place = 'burgerking' create vertex Sitio set place = 'glicinia' # returns #16:2 create edge Puntua from 17:0 to 16:0 set comida = 8, servicio = 9, = extras = 7 create edge Puntua from 17:0 to 16:0 set comida = 8, servicio = 7, = extras = 9 create edge Puntua from 17:0 to 16:2 set comida = 8, servicio = 7, = extras = 9
如果您的情况如上,我相信您正在寻找的查询类似于:
SELECT *, myAvg(comida), myAvg(servicio), myAvg(extras) FROM ( SELECT place, inE('Puntua').comida as comida, inE('Puntua').servicio as servicio, inE('Puntua').extras as extras FROM Sitio )
其中myAvg是一个javascript函数:
var graph = orient.getGraph(); var res = graph.command( "sql", "select avg(list) from (select " + list + " as list)"); if(res.length > 0){ return res[0].getRecord().field('avg'); } else{ return null; }
喜欢这里 (注意列表参数)
输出就是这个 。
EDITED
create class Puntua extends E create class Sitio extends V create class Persona extends V create vertex Persona set name = 'person' # returns #17:0 create vertex Sitio set place = 'mcdonals' # returns #16:0 create vertex Sitio set place = 'burgerking' create vertex Sitio set place = 'glicinia' # returns #16:2 create edge Puntua from 17:0 to 16:0 set comida = 8, servicio = 9, = extras = 7 create edge Puntua from 17:0 to 16:0 set comida = 8, servicio = 7, = extras = 9 create edge Puntua from 17:0 to 16:2 set comida = 8, servicio = 7, = extras = 9
If the above is your situation, I believe the query you're looking for is something like:
SELECT *, myAvg(comida), myAvg(servicio), myAvg(extras) FROM ( SELECT place, inE('Puntua').comida as comida, inE('Puntua').servicio as servicio, inE('Puntua').extras as extras FROM Sitio )
where myAvg is a javascript function:
var graph = orient.getGraph(); var res = graph.command( "sql", "select avg(list) from (select " + list + " as list)"); if(res.length > 0){ return res[0].getRecord().field('avg'); } else{ return null; }
like here. (note the list argument)
The output is this.
相关问答
更多-
暂且不管Collection是否适合这项任务,让我们检查你的代码: 一般 你可能已经这样做了,但它重复了一遍 使用Option Explicit和decalre所有变量 你的守则 Sheets.Add 这会将新Worksheet添加到活动Workbook ,并将其放在当前活动工作表之前,然后激活新工作表。 问题:您依靠默认行为来获取新的Worksheet ,您无法确定新工作表的位置,并且您没有参考它。 建议: 获取对工作簿对象的引用,并在整个代码中使用它 Dim wb As Workbook Set wb ...
-
OrientDB不支持上限集合,但您可以通过使用带回调的挂钩来实现它onAfterCreate()检查大小并删除第一条记录。 OrientDB doesn't support capped collections, but you could implement it by using a hook with a callback onAfterCreate() checks the size and delete the first record.
-
OrientDB平均收集(OrientDB average over collection)[2019-12-18]
EDITED create class Puntua extends E create class Sitio extends V create class Persona extends V create vertex Persona set name = 'person' # returns #17:0 create vertex Sitio set place = 'mcdonals' # returns #16:0 create vertex Sitio set place = 'burger ... -
按日期分组 db.voltage.aggregate([ {$project: { date: {$dateToString: {format: "%Y-%m-%d", date: "$EventTS"}}, KeyValues:1 }}, {$unwind: '$KeyValues'}, {$project: { date: 1, RVoltage: '$KeyValues.RVoltage' }}, ...
-
如何在Scala中迭代来自OrientDB的OResultSet?(How to iterate over OResultSet from OrientDB in Scala?)[2023-08-01]
我已经导入了scala.collection.JavaConversions._,现在迭代工作 I've imported scala.collection.JavaConversions._ and now iterations works -
UPDATE EDGE不支持UPSERT ,请参阅问题#4436 UPDATE EDGE doesn't support UPSERT, see issue #4436
-
尝试这样的事情。 MongoCollection
dbCollection = db.getCollection("example", Document.class); AggregateIterable aggregate = dbCollection.aggregate(Arrays.asList(Aggregates.group("_id", new BsonField("averageAge", new BsonDocument("$avg" ... -
通过lodash进行动态平均计算(Dynamically calculate the average for a nested collection using lodash)[2022-04-24]
您可以使用扩展语法和lodash的_.mergeWith()合并对象。 合并时,如果第二个参数(b)是一个数字除以原始数组中的项目数,以得到它对总平均值的相应贡献。 如果第一个参数(a)是一个数字,只需添加它而不分割(以避免多次除以和),或者如果未定义则加0。 我添加了2个对象数组和3个对象数组的示例。 const getAvg = (data) => _.mergeWith({}, ...data, (a, b) => { if(_.isNumber(b)) { return ((b || ... -
有几种方法可以解决单人文档的问题。 下面的查询$将两个操作数除以$将tests文档减少到其字段( math和science )值的总和,然后是$ size的tests数组来计算平均值。 表达式 $和$$分别引用字段/聚合运算符/聚合阶段和内部变量。 Mongo版本> = 3.4 db.students.aggregate({ $project: { mathAve: {$divide:[{ $reduce: { input: "$tests.sc ...
-
这个解决方案可能会让你更接近你需要的东西,虽然我不确定它是否合适,因为它只是让你计算层次结构选定级别的平均值(即“A”或“A1”)。 这是我的Gremlin会议: gremlin> g = new TinkerGraph() ==>tinkergraph[vertices:0 edges:0] gremlin> a = g.addVertex("a") ==>v[a] gremlin> a1 = g.addVertex("a1") ==>v[a1] gremlin> a2 = g.addVertex(" ...