Skip to content

Instantly share code, notes, and snippets.

@Idosegal
Created August 9, 2023 11:32
Show Gist options
  • Save Idosegal/7ca4c1bc749d5fb4c659da336aa7581b to your computer and use it in GitHub Desktop.
Save Idosegal/7ca4c1bc749d5fb4c659da336aa7581b to your computer and use it in GitHub Desktop.
Problematic code
export async function enter_Search_Result(query) {
let openReportTimeout = 300000;
let reportSearchTitle = "";
try {
let firstResultXpath = Return_First_Element_Xpath("//span[contains(text(),'"+query+"')]");
if (!Wait_For_Selector(firstResultXpath)) {
console_log("enter_Search_Result_00: Failed to find: " + firstResultXpath + " --------");
}
sleep(1);
start = Date.now();
//enter Search
await Promise.all([
global.page.waitForNavigation({
timeout: openReportTimeout,
waitUntil: 'networkidle',
}),
global.page.locator(firstResultXpath).click(),
]);
//await Wait_And_Click("//div[@class='ag-center-cols-container']/div", "Enter Search report", true);
console_log("enter_Search_Result_01: Entering report --------");
screenshot("Loaded_Results_1");
} catch (err) {
screenshot("ERROR_Loaded_Results");
throw new Error("enter_Search_Result: ERROR " + err);
}
}
export async function Wait_For_Selector(elementSelector, elementTimeout = 60000) {
try {
let selectorExists = global.page.waitForSelector(elementSelector, {timeout: elementTimeout});
if (selectorExists != null) {
console_log("Wait_For_Selector: Found selector " + elementSelector);
return true;
}
else {
console_log("Wait_For_Selector: Selector wasn't found " + elementSelector);
return false;
}
} catch (err) {
console_log("Wait_For_Selector: Selector wasn't found " + elementSelector + ". Error: "+ err);
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment