Javascript Can';t用Horseman单击元素
我正在构建一个应用程序,该应用程序将能够允许用户创建作为RSS提要的Google警报 刚从Horseman/PhantomJS开始,我现在在网页上遇到的问题是单击菜单以显示“交付到”选项: 通过浏览器访问此页面并单击您的电子邮件显示位置,将出现一个带有两个选项的小Javascript Can';t用Horseman单击元素,javascript,html,node.js,phantomjs,node-horseman,Javascript,Html,Node.js,Phantomjs,Node Horseman,我正在构建一个应用程序,该应用程序将能够允许用户创建作为RSS提要的Google警报 刚从Horseman/PhantomJS开始,我现在在网页上遇到的问题是单击菜单以显示“交付到”选项: 通过浏览器访问此页面并单击您的电子邮件显示位置,将出现一个带有两个选项的小div,供您选择“RSS提要”。通过Horseman,我找不到点击它的方法。我在点击()后截图查看,但什么都没有。我的代码: horseman .open('https://google.com/alerts') .type(
div
,供您选择“RSS提要”。通过Horseman,我找不到点击它的方法。我在点击()
后截图查看,但什么都没有。我的代码:
horseman
.open('https://google.com/alerts')
.type('input[type="text"]', this.name)
.click('span[class="show_options"]')
.screenshot('/home/gabriel/Desktop/ga-named.png')
.wait(2000)
.click('.delivery_select > div.jfk-select')
.screenshot('/home/gabriel/Desktop/ga-deliver-to.png')
.close()
仅。单击('.delivery\u select>div.jfk-select')
不起作用。在该特定区域的HTML下方:
<div class="delivery_select">
<div class="goog-inline-block goog-flat-menu-button jfk-select" role="listbox" aria-expanded="false" tabindex="0" aria-haspopup="true" style="user-select: none;" aria-activedescendant=":8m">
<div class="goog-inline-block goog-flat-menu-button-caption" id=":8m" role="option" aria-setsize="2" aria-posinset="1">myemail@foo.com</div>
<div class="goog-inline-block goog-flat-menu-button-dropdown" aria-hidden="true">
</div>
</div>
</div>
myemail@foo.com
我认为问题在于它无法使用给定的类单击,请尝试使用不同的id。
检查我如何使用horseman登录
router.post('/login', function (req, res) {
//default urls is http://144.76.34.244:8080/magento/1.9/web/customer/account/login//
var url_ = req.body.url;
var username = req.body.username;
var password = req.body.password;
if (url_.length > 0 && username.length > 0 && password.length > 0) {
horseman
.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0')
.open(url_)
.type('input[name="login[username]"]', username)
.type('input[name="login[password]"]', password)
.click('[name="send"]')
.wait(5000)
.url()
.then(function (url) {
if (url == config.URL) {
res.json({status: "200", msg: 'login successfull', url: url});
} else {
res.json({status: "200", msg: "login failed"});
}
})
.screenshot('big.png')
.close();
} else {
res.json({status: "500", msg: "invalid fields"});
}
});
希望这能有所帮助。我认为问题在于它无法使用给定的类单击,请尝试使用不同的id。 检查我如何使用horseman登录
router.post('/login', function (req, res) {
//default urls is http://144.76.34.244:8080/magento/1.9/web/customer/account/login//
var url_ = req.body.url;
var username = req.body.username;
var password = req.body.password;
if (url_.length > 0 && username.length > 0 && password.length > 0) {
horseman
.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0')
.open(url_)
.type('input[name="login[username]"]', username)
.type('input[name="login[password]"]', password)
.click('[name="send"]')
.wait(5000)
.url()
.then(function (url) {
if (url == config.URL) {
res.json({status: "200", msg: 'login successfull', url: url});
} else {
res.json({status: "200", msg: "login failed"});
}
})
.screenshot('big.png')
.close();
} else {
res.json({status: "500", msg: "invalid fields"});
}
});
希望这能有所帮助。我从未使用过Horseman,但您肯定能够自己实现解决方案
在脚本中单击不起作用,因为该下拉列表未侦听单击:
相反,您可以模拟mousedown:
// Click "Deliver to" dropdown
.evaluate(function(){
var event = document.createEvent ('MouseEvents');
event.initEvent ("mousedown", true, true);
document.querySelector('.delivery_select > div.jfk-select').dispatchEvent(event);
})
我从未使用过Horseman,但您肯定能够自己实现解决方案
在脚本中单击不起作用,因为该下拉列表未侦听单击:
相反,您可以模拟mousedown:
// Click "Deliver to" dropdown
.evaluate(function(){
var event = document.createEvent ('MouseEvents');
event.initEvent ("mousedown", true, true);
document.querySelector('.delivery_select > div.jfk-select').dispatchEvent(event);
})
不幸的是,事实并非如此。更困难的是,我发现点击该选项时显示的
div
实际上是通过JS嵌入的。换句话说,在点击之前,它不存在,我可能很容易点击,甚至隐藏。不幸的是,它不存在。更困难的是,我发现点击该选项时显示的div
实际上是通过JS嵌入的。换句话说,在点击之前,它不存在,我可能很容易点击,甚至隐藏。是的,似乎这就是问题所在,对于这样的元素没有click
事件。我不知道我能查一下,谢谢。根据渲染的图像,它工作了,我看到了应该出现的选项,虽然它没有对齐,但我相信它很好。非常感谢,@VaviloffYea,似乎这就是问题所在,对于这样的元素没有点击事件。我不知道我能查一下,谢谢。根据渲染的图像,它工作了,我看到了应该出现的选项,虽然它没有对齐,但我相信它很好。非常感谢,瓦维洛夫