0% found this document useful (0 votes)
24 views3 pages

Scriptl

vvvvvvvvvvvvv kkkkkkkj

Uploaded by

alaabousmaha014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Scriptl

vvvvvvvvvvvvv kkkkkkkj

Uploaded by

alaabousmaha014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// ==UserScript==

// @name VFS Global Appointment Automation


// @namespace http://tampermonkey.net/
// @version 1.1
// @description Automate VFS Global appointment scheduling
// @match https://row7.vfsglobal.com/Global-Appointment/Home/Index*
// @match
https://row7.vfsglobal.com/Global-Appointment/Applicant/ApplicantList*
// @match
https://row7.vfsglobal.com/Global-Appointment/Applicant/AddApplicant*
// @grant none
// ==/UserScript==

(function() {
'use strict';

// Function to click a specific button on the Home/Index page


async function clickHomeIndexButton() {
console.log('Attempting to click button on Home/Index page...');
await waitForElement('//*[@id="Accordion1"]/div/div[2]/div/ul/li[1]/a');
let homeIndexButton =
document.evaluate('//*[@id="Accordion1"]/div/div[2]/div/ul/li[1]/a', document,
null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

if (homeIndexButton) {
homeIndexButton.click();
console.log('Button on Home/Index page clicked');
} else {
console.error('Button on Home/Index page not found');
}
}

// Function to click "Continue" button on Applicant List page


async function clickContinueOnApplicantList() {
console.log('Attempting to click "Continue" on Applicant List...');
await waitForElement('/html/body/div[2]/div[1]/div[3]/div[3]/a');
let continueButton =
document.evaluate('/html/body/div[2]/div[1]/div[3]/div[3]/a', document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

if (continueButton) {
continueButton.click();
console.log('"Continue" button clicked on Applicant List');
} else {
console.error('"Continue" button on Applicant List not found');
}
}

// Function to click "Submit" button on Applicant List form on the second visit
async function clickSubmitOnSecondApplicantList() {
console.log('Attempting to click "Submit" on second visit to Applicant
List...');
await waitForElement('//*[@id="ApplicantListForm"]/div[2]/input');
let submitButton =
document.evaluate('//*[@id="ApplicantListForm"]/div[2]/input', document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

if (submitButton) {
submitButton.click();
console.log('"Submit" button clicked on second visit to Applicant
List');
} else {
console.error('"Submit" button on second visit to Applicant List not
found');
}
}

// Function to fill in the applicant form


async function fillApplicantForm() {
console.log('Filling in applicant form...');
await waitForElement('/html/body/div[2]/div[1]/div[3]/div[4]/form/div[1]/
div[2]/input');

let numberField =
document.evaluate('/html/body/div[2]/div[1]/div[3]/div[4]/form/div[1]/div[2]/
input', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
let nameField =
document.evaluate('/html/body/div[2]/div[1]/div[3]/div[4]/form/div[3]/div[2]/
input', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
let surnameField =
document.evaluate('/html/body/div[2]/div[1]/div[3]/div[4]/form/div[4]/div[2]/
input', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
let selectField =
document.evaluate('/html/body/div[2]/div[1]/div[3]/div[4]/form/div[2]/div[2]/
select', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,
null).singleNodeValue;
let nationalityDropdown = document.evaluate('//*[@id="NationalityId"]',
document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
let nationalityOption =
document.evaluate('//*[@id="NationalityId"]/option[4]', document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

if (numberField && nameField && surnameField && selectField &&


nationalityDropdown && nationalityOption) {
numberField.value = '123456';
nameField.value = 'Sifo';
surnameField.value = 'belkcm';
selectField.value = nationalityOption.value;
selectField.dispatchEvent(new Event('change'));
console.log('Applicant form filled');
} else {
console.error('Form fields or dropdown not found');
}
}

// Wait for an element to be available


function waitForElement(xpath) {
return new Promise((resolve, reject) => {
let interval = setInterval(() => {
let element = document.evaluate(xpath, document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (element) {
clearInterval(interval);
resolve(element);
}
}, 500);
});
}
// Main script execution
window.addEventListener('load', async () => {
console.log('Page loaded. Starting script...');

if (window.location.href.includes('Home/Index')) {
await clickHomeIndexButton();
}

if (window.location.href.includes('Applicant/ApplicantList')) {
if (window.location.href.includes('ApplicantList')) {
await clickContinueOnApplicantList();
await clickSubmitOnSecondApplicantList();
}
}

if (window.location.href.includes('AddApplicant')) {
await fillApplicantForm();
}
});
})();

You might also like