How to scroll down in Rselenium until a specific date appear in facebook - facebook

I a working with facebook and I want scroll one page until the first publication of 2020 appears. The problem is that I can't get the html text for each date at the same time that the code is scrolling down. This my code:
tryCatch({
Sys.sleep(2)
suppressMessages({
vermas <- remDr$findElement("css", "body")
fecha_mirar <- remDr$findElement("css",".x4k7w5x.x1h91t0o.x1h9r5lt.x1jfb8zj.xv2umb2.x1beo9mf.xaigb6o.x12ejxvf.x3igimt.xarpa2k.xedcshv.x1lytzrv.x1t2pt76.x7ja8zs.x1qrby5j")
fecha <- as.character(fecha_mirar$getElementText())
while(fecha != "[2020]"){
vermas$sendKeysToElement(list(key = "end"))
vermas$sendKeysToElement(list(key = "enter"))
Sys.sleep(5)
fecha_mirar <-remDr$findElement("css",".x4k7w5x.x1h91t0o.x1h9r5lt.x1jfb8zj.xv2umb2.x1beo9mf.xaigb6o.x12ejxvf.x3igimt.xarpa2k.xedcshv.x1lytzrv.x1t2pt76.x7ja8zs.x1qrby5j")
fecha <- as.character(fecha_mirar$getElementText())
}
})
},
error = function(e) {
NA_character_
}
)
The idea of the code is scroll the facebook page until one publication is from 2020 and the code give me a NA to continue with other code.
The problem is that the only date that I get is from the first publication and I can't figure out how to solve it.
Thanks community!!!
PD: You can check the code in any facebook page.

Related

How to select date of datepicker in protractor

I am automating the application through protractor and as part of one testcase need to select the date, the date-picker definition is as below. I tried to select the date using sendkeys which is not working.
element(by.lid("new-transaction-doat-field)).sendKeys("24 Aug 2019");
Please help me in to select the date.
Note: lid is the custom attribute and to select the value by lid, create a custom attribute method in protractor
Two issues in your given code:
1) Should interact with a Input html element
2) sendKeys() can't interact with a readonly Input html element.
// because protractor not support invoke setAttribute api directly,
// need to using executeScript to inject DOM Javascript snippet into browser
// then execute the snippet in browser
browser.executeScript(
"arguments[0].setAttribute('value', arguments[1])",
element(by.css( '[lid="new-transaction-doat-field"] > span > input')).getWebElement(),
"24 Aug 2019"
)
Keep in mind, setAttribute() is not simulating user interact with web page from UI.
Please confirm it's acceptable from your test perspective.
I found the solution to select the date through datepicker where 'sendKeys' won't work as input is disabled. The solution is like how manually we will traverse through the calendar and select the date.
The code is as below:
this.selectDate = function (dateElement, dateValue, yearButton, arrowButton) {
var splitDate = dateValue.split('/');
var year = splitDate[2];
var month = splitDate[1];
var day = splitDate[0];
var monthName = getMonthName(month);
dateElement.click()
.then(() => yearButton.click())
.then(() => yearButton.click())
.then(() => selectYear(year, arrowButton))
.then(() => element(by.xpath("//span[text()='" + year + "']")).click())
.then(() => element(by.xpath("//span[text()='" + monthName + "']")).click())
.then(() => element(by.xpath("//span[text()='" + day + "']")).click());
};
async function selectYear(year, arrowButton) {
for(var i=0; i < 10; i++) {
var present = await element(by.xpath("//span[text()='" + year + "']")).isPresent()
if(present) {
break;
} else {
await arrowButton.click();
}
}
}
function takes inputs as dateElement, dateValue, yearButton - which is center button to traverse to years, arrowButton - previous or next button in the calendar
First script clicks on the year button in the center in the above image it is 'September 2019' , after that '2019' year calendar comes, it clicks on that again.
Then 2001 to 2019 calendar comes as below
if the year displays it clicks on that otherwise it clicks on 'previous' or 'next' button based on the date to select until it got displayed (looping for 10 times to search for the year, if not in 10 clicks throws error).
After year clicked, it clicks on month and day.
have you tried the .sendKeys() on the input?
element(by.model('dateModel')).sendKeys('dd mmm yyyy');

Query Waypoints need to scroll in both directions

I am using jQuery-waypoints and the infinite shortcut to load listings on my page. I have this all working and am trying to comply with Google's Guidelines on this by using pushState() to alter the browsers history. This is all working fine using this.
if ($('#list-col.active .list-col-content').length > 0 && !wayPoints) {
initWaypoint();
}
;
function initWaypoint() {
let infinite = new Waypoint.Infinite({
element: $('#list-col.active .list-col-content'),
offset: function () {
return this.context.innerHeight() - this.adapter.outerHeight() + 2000
},
onAfterPageLoad: function (direction) {
var last = $('.page-loaded:last');
last.waypoint(function (direction) {
if (direction == 'down') {
if (window[window.GoogleAnalyticsObject]) {
ga('set', 'page', last.data('url'));
ga('send', 'pageview');
console.log('pageview ' + last.data('url'));
}
history.pushState('', last.data('title'), last.data('url'));
} else {
history.pushState('', last.data('prev_title'), last.data('prev_url'));
}
})
}
});
wayPoints = true;
};
Here is my issue/questions.
The new browser's URL is now https://www.example.com/listingpage?page=15. Per Google's Guidelines, that "component page" needs to load content with page 15's listings, and only page 15's content. No problem, I can do that. But now I have an issue with the content BEFORE page 15.
I now need to scroll up, loading more content (now above the existing content) as the user scrolls up.
I am at a loss on how to add a second infinite (really finite since it is loading down to 0) scroller that loads pages as you scroll up the page.
I know I am not the first to encounter this so any help or direction would be appreciated.
No responses in several days so I researched and found an answer on my own. Posting some info here in case anyone else has same issue with infinite scrolling in both directions.
Best solution I found was on Google's Infinite Scroll search-friendly recommendations. That pages lists an infinite scroll with pagination demo. I had to do some modification for my specific use, but it is a great example and obviously following Google's recommendation is a good way to go.
Hope this helps someone.

trigger fancybox iframe without click but when a condition is met

Simple question, I dont think its possible but hopefully someone can proof me wrong.
Is it possible to trigger fancybox without a click but rather if an event is met
Example
if(balance<1){
#fancyBoxOpen
}
else{
Continue to page
}
Yes, it's possible.
You could create a function that triggers fancybox like :
var triggerFancybox = function () {
var content = "Sorry, the balance is less than 1";
jQuery.fancybox.open(content);
}
And call that function when your condition is met like :
if (balance < 1) {
triggerFancybox();
}
See JSFIDDLE
.... or another with a hard-coded condtion

Facebook page update script

I have a greasemonkey script that tries to make a status update when a facebook page loads.
But when I try to submit, I get the message:
"This status update appears to be blank. Please write something or
attach a link or photo to update your status."
I am guessing that I am bypassing some input validation routine that is called when a real user types in the status.
Here is what I have beem trying.
Consider a FB page like: https://www.facebook.com/IFeakingLoveScience
function setmsg()
{
textHolder.focus();
var vntext=textHolder.value;
textHolder.value = postvalue;
textHolder.focus();
postbutton = document.getElementsByClassName( "_42ft _4jy0 _11b _4jy3 _4jy1" )[0];
postbutton.focus();
textHolder.focus();
setTimeout(postmsg, 4000); // Give the link in post value load.
}
function postmsg()
{
textHolder.focus();
textHolder = document.getElementsByClassName( "uiTextareaAutogrow input mentionsTextarea textInput" )[0];
textHolder.value = postvalue1 + "\n" + postvalue2; // set the value again just in case that helps...
textHolder.focus();
postbutton.click();
}
setTimeout(setmsg, 1000); // give a sec for the page to load
Any clues?
Regards,
Manoj
Assuming you are running your script on your 'Home' page on facebook, set your status update as the value of the hidden input named "xhpc_message" .
//set input value
document.getElementsByName('xhpc_message')[0].value = 'yourstatusupdategoeshere';
//submit button click
document.getElementsByClassName('_42ft _4jy0 _11b _4jy3 _4jy1 selected')[0].click()

jQuery Mobile checkbox takes time to get checked/unchecked on iPhone

I am facing an issue with jQuery Mobile on iPhone.
I have a list of checboxes and a checkbox to select "All".
After an initial few taps on the checkbox, the check box takes few seconds to get marked as checked/unchecked.
The checkbox doesnt get marked unless the user waits for a few seconds or scroll the screen.
This seems to be an issue only with this particular phone as it works fine on desktop browsers and Android devices.
Here is the script:
/* Check-Uncheck */
self.elements.listview.on('change', ':checkbox', function (event) {
var unchecked = $(':checkbox:not(:checked)', self.elements.listview);
self.elements.selectAll
.prop('checked', unchecked.length === 0)
.checkboxradio("refresh");
});
/* Check-Uncheck 'Select All' */
self.elements.selectAll.change(function () {
var checkboxes = $(':checkbox', self.elements.listview);
var checked = self.elements.selectAll.is(':checked');
checkboxes
.prop('checked', checked)
.checkboxradio("refresh");
});
Please let me know if anyone has faced this particular issue, or have any suggestions.
Thanks