I'm trying to get the news comments on yahoo, where there is a link "See reactions", with the following id: "caascommtbar-wide" and tried to get the element with CasperJS, Selenium, ScrapySharp, to click on the link and display the comments, but in those tools you never find the element and I've even tried using the XPath
CasperJS:
casper.then (function () {
if (this.exists ('a.caascommtbar-anchor')) {
this.echo ("It exists");
} else
this.echo ("It Does not Exist");
});
casper.then (function () {
// Click on 1st result link
this.click ('a.caascommtbar-anchor');
});
Selenium:
driver.FindElement (By.Id ("caascommtbar-anchor")). Click ();
Does anyone know why you can not access this part of the HTML code where the comments are located?
It should be noted that the same thing happens to me when trying to access the Facebook comments contained in the news forums.
As Isaac said the part of pages are loaded asynchronously, so you should implement waitFor steps in your code. Here is the code that does just that.
var url = "https://es-us.vida-estilo.yahoo.com/instagram-cierra-la-cuenta-de-una-modelo-por-ser-gorda-103756072.html";
var casper = require('casper').create({
viewportSize: {width: 1280, height: 800},
});
casper.start(url, function() {
this.echo('Opened page');
});
casper.waitForSelector('a.comments-title', function() {
this.click('.comments-title');
});
casper.waitForSelector('ul.comments-list > li', function() {
this.echo(this.getHTML('ul.comments-list'));
});
casper.run();
Hope that helps
The problem was why the page was not loaded yet and I had to wait, I'm new with casperjs.
Now I have the problem when trying to remove all comments along with their answers, but can not find an algorithm to help me. Try to press all the answer buttons, but only get the first answers to the first comments.
casper.waitForSelector('button.showMore', function () {
this.click('.showMore');
}, function onWaitTimeout() {
});
var buttons;
casper.waitForSelector('ul.comments-list', function getLinks() {
buttons = this.evaluate(function ()
{
var buttons = document.getElementsByClassName('replies-button');
buttons = Array.prototype.map.call(buttons, function (button) {
button.click();
casper.waitForSelector('ul.comments-list', function () {
casper.wait(3000, function () {
});
});
return button.getAttribute('class');
});
return buttons;
});
}, function onWaitTimeout() {
});
function wait5seconds() {
casper.wait(3000, function () {
});
}
casper.waitForSelector('ul.comments-list > li', function () {
var x = this.getHTML('ul.comments-list');
this.echo(x);
}, function onWaitTimeout() {
});
casper.run();
Related
I have a website and in my html code I have added barba.js, If I go to inner pages barba animations are working fine, but other javascript functions are not working.
So i added this barba script in html page,
$('document').ready(function(){
//initIndexJs();
var transEffect = Barba.BaseTransition.extend({
start: function(){
this.newContainerLoading.then(val => this.fadeInNewcontent($(this.newContainer)));
},
fadeInNewcontent: function(nc) {
nc.hide();
var _this = this;
$(this.oldContainer).fadeOut(1000).promise().done(() => {
nc.css('visibility','visible');
nc.fadeIn(1000, function(){
_this.done();
})
});
},
});
Barba.Dispatcher.on('transitionCompleted', function(currentStatus, oldStatus, container) {
initIndexJs();
//callForPageLoad();
});
Barba.Pjax.getTransition = function() {
return transEffect;
}
Barba.Pjax.start();
});
So can anyone please help me to solve this problem?
I was trying to see if element enabled on the page before clicking on that. I want to create command that will check if element is enabled or not before clicking on it. I was going over API of nightwatch and still not sure how this commands works. I was trying following:
browserObj.elementIdEnabled(Cssselector, function (res) {
console.log(res);
});
But I think I should pass something else and not css selector into elementIdEnabled function. Ideally I want to chain 3 commands before clicking on element:
browserObj.perform(function () {
this.waitForElementPresent(cssSelector, timeout, function () {
this.waitForElementVisible(cssSelector, timeout, function () {
this.api.elementIdEnabled(cssSelector, function (res) {
browserObj.click(cssSelector, function (clickStatus) {
this.assert.equal(clickStatus.status, 0 );
});
})
})
});
});
module.exports.command = function (selector) {
this.waitForElementVisible(selector).click(selector);
return this;
};
By beatfactor from
https://github.com/nightwatchjs/nightwatch/issues/705
I want to create a button for change pages. My problem is, I have a code that i wrote before but it works not that way i would like to.
Here's the code:
function loadingPage() {
$(function () {
$(".content").load("home.html");
});
}
function loadingPage_about() {
$(function () {
$(".content").load("about.html");
});
}
button1.onclick = loadingPage;
button2.onclick = loadingPage_about;
I want to cut this code using a one function and later change pages in attributes. Something like this:
function loadingPage(page) {
$(function () {
$(".content").load(page);
});
}
button1.onclick = loadingPage("home.html");
button2.onclick = loadingPage("about.html");
But it doesn't work, page is automaticly loaded after window.onload and buttons doesnt change the content section. Can someone tell me why this code doesnt work? :/
Here, loadingPage is executed immediately and the result is assigned to button.onclick:
button1.onclick = loadingPage("home.html");
To delay the execution, you could e.g. wrap it in a function:
button1.onclick = function() {loadingPage("home.html")};
Yup! It works! I wrote a return in main function and I dont need to wrap every call to loadingPage()
Here's the code:
function loadingPage(page) {
return function () {
$(function () {
$(".content").load(page);
});
}
}
button1.onclick = loadingPage("home.html");
button2.onclick = loadingPage("about.html");
button3.onclick = loadingPage("info.html");
Really thank you guys! You're amazing! :)
HI I am trying to implement an embed and share options for one of my webpages. Not sure why but the code wont do anything and its not showing any errors on console.
fiddle
https://jsfiddle.net/jt129L49/2/
function embedButton() {
d3.select('.btn-embed').on ("click", function() {
d3.select('.Stage-popup').hide();
d3.select('.Stage-popup-embed').show();
});
d3.select('.btn-faq').on ("click", function()
{ d3.select('.Stage-popup').hide();
d3.select('.Stage-popup-faq').show(); });
d3.select('.Stage-popup .popup-close-btn').on ("click", function() { d3.select('.Stage-popup').hide() });
}
okay so I need this script
$(document).ready(function() {
$('a[id="twittersocial"]').click(function() {
$(".twittersocial").slideToggle("slow", function() {
$(".twittersocial").load('social/twitter.php?k=<?php echo"$website"; ?>', function() {});
});
});
});
to run when someone goes to the direct url
www.website.com#twittersocial
and when of course when somene click the link
twitter social
How can I achieve this ?
When the page is loaded, check whether the hash is set and run your code. Put the code in a function so you can call it from both the event handler and at startup.
$(function() {
function loadTwitterSocial() {
$(".twittersocial").slideToggle("slow", function() {
$(".twittersocial").load('social/twitter.php?k=<?php echo"$website"; ?>', function() {});
});
}
if (location.hash == "#twittersocial") {
loadTwitterSocial();
}
$('a#twittersocial').click(loadTwitterSocial);
}