save work
This commit is contained in:
12
src/index.ts
12
src/index.ts
@ -23,7 +23,7 @@ async function visitCityPages(): Promise<void> {
|
||||
|
||||
console.log('Connecting to existing Chrome browser...');
|
||||
|
||||
const driver = await useChrome();
|
||||
const driver = await useExistingChrome();
|
||||
if (!driver) return;
|
||||
|
||||
// Visit each city's TripAdvisor page
|
||||
@ -48,14 +48,10 @@ async function visitCityPages(): Promise<void> {
|
||||
await WebDriverUtils.wait(driver);
|
||||
|
||||
console.log("Click See all")
|
||||
let seeAllUrl = await UIActions.getSeeAllUrl(driver);
|
||||
|
||||
if (seeAllUrl.length == 0) {
|
||||
if (!await UIActions.clickSeeAllAttractions(driver)) {
|
||||
if (!await UIActions.clickTourismLink(driver)) throw `${city} failed`;
|
||||
seeAllUrl = await UIActions.getSeeAllUrl(driver);
|
||||
if (!await UIActions.clickSeeAllAttractions(driver)) throw `${city} failed`;
|
||||
}
|
||||
|
||||
if (seeAllUrl.length == 0) throw `${city} failed`;
|
||||
await WebDriverUtils.wait();
|
||||
|
||||
console.log("Switch tab")
|
||||
@ -69,7 +65,7 @@ async function visitCityPages(): Promise<void> {
|
||||
}
|
||||
|
||||
console.log("Click See all attractions")
|
||||
if (!await UIActions.getSeeAllAttractionsUrl(driver)) throw `${city} failed`;
|
||||
if (!await UIActions.clickSeeAllAttractions(driver)) throw `${city} failed`;
|
||||
await WebDriverUtils.wait();
|
||||
|
||||
console.log("Switch tab to Attraction")
|
||||
|
||||
@ -80,7 +80,7 @@ export async function gotoHome(driver: WebDriver): Promise<boolean> {
|
||||
}
|
||||
|
||||
export async function clickSeeAllAttractions(driver: WebDriver): Promise<boolean> {
|
||||
const xpath = `//h2[starts-with(normalize-space(.), 'Top Attractions in')]/parent::*[1]//a[starts-with(@href, '/Attractions') and .//span[normalize-space(.)='See all']]`;
|
||||
const xpath = `//h3[starts-with(normalize-space(.), 'Things to do')]/parent::*[1]//a[starts-with(@href, '/Attractions') and .//span[normalize-space(.)='See all']]`;
|
||||
|
||||
try {
|
||||
const anchorElement = await driver.wait(until.elementLocated(By.xpath(xpath)), 5000);
|
||||
@ -98,7 +98,7 @@ export async function clickSeeAllAttractions(driver: WebDriver): Promise<boolean
|
||||
}
|
||||
|
||||
export async function getSeeAllAttractionsUrl(driver: WebDriver): Promise<string | null> {
|
||||
const xpath = `//h2[starts-with(normalize-space(.), 'Top Attractions in')]/parent::*[1]//a[starts-with(@href, '/Attractions') and .//span[normalize-space(.)='See all']]`;
|
||||
const xpath = `//h3[starts-with(normalize-space(.), 'Top Attractions in')]/parent::*[1]//a[starts-with(@href, '/Attractions') and .//span[normalize-space(.)='See all']]`;
|
||||
|
||||
try {
|
||||
const anchorElement = await driver.wait(until.elementLocated(By.xpath(xpath)), 5000);
|
||||
|
||||
@ -25,15 +25,9 @@ export class WebDriverUtils {
|
||||
while (Date.now() < endTime) {
|
||||
try {
|
||||
if (driver) {
|
||||
if(scrollCounter < 4){
|
||||
await driver.executeScript(`
|
||||
window.scrollBy(0, window.innerHeight);
|
||||
window.scrollBy(0, 10);
|
||||
`);
|
||||
}else{
|
||||
await driver.executeScript(`
|
||||
window.scrollTo(0, 0);
|
||||
`);
|
||||
}
|
||||
|
||||
scrollCounter++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user