Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Limit for clicking #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Selectors/Element click selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ events triggered by the button.
be clicked to load more elements.
* click type - type of how the selector knows when there will be no new
elements and clicking should stop.
* click limit - the number of clicks you want the selector to perform.
* click element uniqueness - type of how selector knows which buttons are
already clicked.
* multiple - multiple records are being extracted (almost always should be
Expand Down
11 changes: 10 additions & 1 deletion extension/devtools/views/SelectorEdit.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
</div>
</div>

<!-- ClickLimit -->
<div class="form-group feature feature-clickLimit">
<label for="clickLimit" class="col-lg-1 control-label">Click Limit</label>

<div class="col-lg-10">
<input type="text" class="form-control" name="clickLimit" id="clickLimit" placeholder="clickLimit" value="{{selector.clickLimit}}">
</div>
</div>

<!-- clickElementUniquenessType -->
<div class="form-group feature feature-clickElementUniquenessType">
<label for="clickElementUniquenessType" class="col-lg-1 control-label">Click element uniqueness</label>
Expand All @@ -110,7 +119,7 @@
</label>
</div>
</div>
</div>
</div>

<!-- discardInitialElements -->
<div class="form-group feature feature-discardInitialElements">
Expand Down
15 changes: 12 additions & 3 deletions extension/scripts/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,13 @@ SitemapController.prototype = {
}
}
},
clickLimit: {
validators: {
numeric: {
message: 'Click limit must be numeric'
}
}
},
parentSelectors: {
validators: {
notEmpty: {
Expand Down Expand Up @@ -830,7 +837,7 @@ SitemapController.prototype = {
var sitemap = this.state.currentSitemap;
var selector = this.state.currentSelector;
var newSelector = this.getCurrentlyEditedSelector();

// cancel submit if invalid form
if(!this.isValidForm()) {
return false;
Expand Down Expand Up @@ -863,6 +870,7 @@ SitemapController.prototype = {
var clickPopup = $("#edit-selector [name=clickPopup]").is(":checked");
var regex = $("#edit-selector [name=regex]").val();
var delay = $("#edit-selector [name=delay]").val();
var clickLimit = $("#edit-selector [name=clickLimit]").val();
var extractAttribute = $("#edit-selector [name=extractAttribute]").val();
var parentSelectors = $("#edit-selector [name=parentSelectors]").val();
var columns = [];
Expand Down Expand Up @@ -898,7 +906,8 @@ SitemapController.prototype = {
extractAttribute:extractAttribute,
parentSelectors: parentSelectors,
columns:columns,
delay:delay
delay:delay,
clickLimit:clickLimit
});
return newSelector;
},
Expand Down Expand Up @@ -1004,7 +1013,7 @@ SitemapController.prototype = {

var requestInterval = $("input[name=requestInterval]").val();
var pageLoadDelay = $("input[name=pageLoadDelay]").val();

var sitemap = this.state.currentSitemap;
var request = {
scrapeSitemap: true,
Expand Down
8 changes: 5 additions & 3 deletions extension/scripts/Selector/SelectorElementClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var SelectorElementClick = {
_getData: function(parentElement) {

var delay = parseInt(this.delay) || 0;
var clickLimit = parseInt(this.clickLimit) || 1;
var deferredResponse = $.Deferred();
var foundElements = new UniqueElementList('uniqueHTMLText');
var clickElements = this.getClickElements(parentElement);
Expand Down Expand Up @@ -109,7 +110,7 @@ var SelectorElementClick = {

// infinitely scroll down and find all items
var interval = setInterval(function() {

// find those click elements that are not in the black list
var allClickElements = this.getClickElements(parentElement);
clickElements = [];
Expand Down Expand Up @@ -145,7 +146,7 @@ var SelectorElementClick = {
// continue clicking and add delay, but if there is nothing
// more to click the finish
//console.log("total buttons", clickElements.length)
if(clickElements.length === 0) {
if(clickElements.length === 0 || clickLimit < 1) {
clearInterval(interval);
deferredResponse.resolve(foundElements);
}
Expand All @@ -158,6 +159,7 @@ var SelectorElementClick = {
}
this.triggerButtonClick(currentClickElement);
nextElementSelection = now+delay;
clickLimit--;
}
}.bind(this), 50);

Expand All @@ -169,6 +171,6 @@ var SelectorElementClick = {
},

getFeatures: function () {
return ['multiple', 'delay', 'clickElementSelector', 'clickType', 'discardInitialElements', 'clickElementUniquenessType']
return ['multiple', 'delay', 'clickElementSelector', 'clickType', 'discardInitialElements', 'clickElementUniquenessType', 'clickLimit']
}
};