The clickSpa
function simulates a click on an element with a specific profile URL by appending an a
element to the page and executing a command to click on it, waiting for 1 second before resolving.
The clickSpa
function simulates a click on an element with a specific profile URL by creating an a
element and setting up an event listener to remove it after a delay. The function waits for 1 second before resolving the promise, and catches any errors that occur during execution.
npm run import -- "click spa link"
function clickSpa(client, profile) {
return client
.getUrl()
.then(url => url.indexOf(profile) > -1
? []
: client
.execute(url => {
var a = document.createElement('a');
a.setAttribute('href', url);
a.setAttribute('class', 'spa');
a.onclick = () => setTimeout(() => document.body.removeChild(a), 500)
a.href = url;
a.style.position = 'absolute';
a.style.zIndex = 4294967295;
a.style.top = 0;
a.style.left = 0;
a.style.bottom = 0;
a.style.right = 0;
document.body.appendChild(a);
}, profile)
.click('a.spa[href*="' + profile + '"]')
.pause(1000))
.catch(e => console.log(e))
};
module.exports = clickSpa;
/**
* Simulates a click on a SPA link.
*
* @param {object} client - The client instance.
* @param {string} profile - The profile to search for.
* @returns {object} A promise that resolves with an array.
*/
function clickSpa(client, profile) {
// Get the current URL
return client
.getUrl()
.then((url) => {
// Check if the profile is already in the URL
if (url.includes(profile)) {
// If it is, return an empty array immediately
return [];
}
// If not, execute a script to create a SPA link
return client
.execute(() => {
// Create a new anchor element
const a = document.createElement('a');
// Set the href attribute
a.setAttribute('href', profile);
// Set the class attribute
a.setAttribute('class','spa');
// Set the onclick event to remove the element after 500ms
a.onclick = () => setTimeout(() => document.body.removeChild(a), 500);
// Make the element clickable
a.href = profile;
// Set some CSS styles to make the element visible
a.style.position = 'absolute';
a.style.zIndex = 4294967295;
a.style.top = 0;
a.style.left = 0;
a.style.bottom = 0;
a.style.right = 0;
// Add the element to the body
document.body.appendChild(a);
})
.then(() => {
// Wait for the element to be loaded and click it
return client.pause(1000).then(() => client.click('a.spa'));
});
})
.catch((e) => console.log(e));
}
module.exports = clickSpa;
clickSpa(client, profile)
client
: Client objectprofile
: Profile URL or keywordclient.getUrl()
a
element with the profile URL as its href
attribute and appends it to the document body. The a
element has a spa
class and is styled to cover the entire screen.a
element to remove it after a 500ms delay.a
element with the spa
class and a href
attribute containing the profile URL.pause(1000)
before resolving the promise.Note: This code is likely part of a Selenium or Puppeteer testing framework and is used to simulate a click on an element with a specific profile URL.