1

I am using a slider in wordpress that does not include anchors to allow us to link to a specific section.

Is it possible to navigate a user to a URL and simulate the user pressing down arrow or clicking a button 3 times with java or selenium.

We can anchor to a text block but how the split screen slider functions this does load the page correctly.

We are developing locally but here is the theme example. I am attempting to link to slide 3. http://tahoe.edge-themes.com/split-screen-slider/

Backend functionality is not my strong suit. Thank you.

Dean
  • 11
  • 2
  • Be a lot simpler to wrap some links into a slider – charlietfl Nov 24 '18 at 00:20
  • Not sure this will work in this case. We can anchor to a text block but how the slider functions the image does not load with the relevant text. Thank you. – Dean Nov 24 '18 at 03:27

1 Answers1

0

I can only see a way to do this using JavaScript, inject the following in to the page, making changes where needed:

// Get a reference to the button element needing to be clicked

var button = document.querySelector("button");

// Use the following function:

navigateToPage(button, "page");

// Link to page with query string of `?page=[n]` (see URL),
// then click the specified element n times

function navigateToPage(button, queryParamName) {
  var times = parseInt(getQueryVariable(queryParamName), 10);
  for (var i = 0; i < times; i++) {
    button.click();
  }
}

// Taken from: https://stackoverflow.com/questions/2090551/parse-query-string-in-javascript
// ----
// If you don't need to support IE 11, see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/get
// for a more native solution to fetch query params.

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    if (decodeURIComponent(pair[0]) == variable) {
      return decodeURIComponent(pair[1]);
    }
  }
  return variable;
}

See the following Codesandbox for a live example:

https://codesandbox.io/s/ox0k1y16k6

Watch how many times the button is clicked based off the query parameter in the URL:

https://ox0k1y16k6.codesandbox.io/?page=3

https://ox0k1y16k6.codesandbox.io/?page=10