Trying to clean the site. For this, I want to automate a button click. I can't seem to get the button to do anything.
Link: http://shop.nordstrom.com/s/polo-ralph-lauren-pajama-pants/2849416
Website : ReactJS, JQueryJS
Button selection: # product-selection-2849416> section.color-filter> div> ul> li: nth-child (2)> a> span> span.image-sprite -image.cover> span> img
Attempts
JQuery click, mousedown, touchstart and native click ... In the Chrome Dev Tools console.
$("#product-selection-2849416 > section.color-filter > div > ul > li:nth-child(2) > a > span > span.image-sprite-image.cover > span > img").click()
$("#product-selection-2849416 > section.color-filter > div > ul > li:nth-child(2) > a > span > span.image-sprite-image.cover > span > img")[0].click()
$("#product-selection-2849416 > section.color-filter > div > ul > li:nth-child(2) > a > span > span.image-sprite-image.cover > span > img").mousedown()
$('#product-selection-2849416 > section.color-filter > div > ul > li:nth-child(2) > a > span > span.image-sprite-image.cover > span > img').trigger('touchstart');
PhantomJS function sendEvent ... Via a browser without a PhantomJS browser.
var webpage = require('webpage');
var page = webpage.create();
var href = "http://shop.nordstrom.com/s/polo-ralph-lauren-pajama-pants/2849416";
page.open(href, function (status) {
var elem = "#product-selection-2849416 > section.color-filter > div > ul > li:nth-child(2) > a > span > span.image-sprite-image.cover > span > img";
var rect = page.evaluate(function(elem) {
return $(elem)[0].getBoundingClientRect();
}, elem);
function computeCenter(bounds) {
var x = Math.round(bounds.left + bounds.width / 2);
var y = Math.round(bounds.top + bounds.height / 2);
return [x, y];
}
var cor = computeCenter(rect);
page.sendEvent('click', cor.x, cor.y, 'left');
setTimeout(function() {
page.render('websiteAfterClick.png');
page.close();
}, 1000);
}
And HTML events ... In the Chrome Dev Tools console.
var elem = $("#product-selection-2849416 > section.color-filter > div > ul > li:nth-child(2) > a > span > span.image-sprite-image.cover > span > img")[0];
var evt = document.createEvent("MouseEvents");
var center_x = 1, center_y = 1;
try {
var pos = elem.getBoundingClientRect();
center_x = Math.floor((pos.left + pos.right) / 2);
center_y = Math.floor((pos.top + pos.bottom) / 2);
} catch(e) {}
evt.initMouseEvent('click', true, false, window, 1, 1, 1, center_x, center_y, false, false, false, false, 0, elem);
... PhantomJS.
var webpage = require('webpage');
var page = webpage.create();
var href = "http://shop.nordstrom.com/s/polo-ralph-lauren-pajama-pants/2849416";
page.open(href, function (status) {
page.includeJs("https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react-with-addons.js", function() {
var elem = "#product-selection-2849416 > section.color-filter > div > ul > li:nth-child(2) > a > span > span.image-sprite-image.cover > span > img";
page.evaluate(function(elem) {
React.addons.TestUtils.Simulate.click($(elem)[0]);
}, elem);
setTimeout(function() {
page.render('websiteAfterClick.png');
page.close();
}, 1000);
});
}
. - , , ... Chrome Dev Tools.
$('#product-selection-2849416 > section.color-filter > div > select').val('Black Royal Oxford').change();
$('#product-selection-2849416 > section.color-filter > div > select').val('Black Royal Oxford').trigger('change');
React. , . , ...
WebDriver Selenium . PhantonJS.
, , . ...
XPath. , . .
- ? , .