Skip to content

Commit 18af9ab

Browse files
committed
wait for input element before attempting search
1 parent ce699c0 commit 18af9ab

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/api/search.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ export class Search extends Instagram<TSearchResult> {
108108
await this.start();
109109
}
110110
try {
111-
const inputElement = await this.page.$(this.inputElementQuery);
112-
if (inputElement === null) {
113-
const pageContent = await this.page.content();
114-
this.logger.error("Couldn't find input", {
115-
content: pageContent,
116-
});
117-
}
111+
const inputElement = await this.page.waitForSelector(
112+
this.inputElementQuery,
113+
{timeout: 30000},
114+
);
118115

119116
await inputElement.click();
120117
await this.page.keyboard.sendCharacter(this.searchQuery);
@@ -125,6 +122,11 @@ export class Search extends Instagram<TSearchResult> {
125122
await this.stop();
126123
return this.searchResult;
127124
} catch (e) {
125+
const pageContent = await this.page.content();
126+
this.logger.error(e.message, {
127+
content: pageContent,
128+
});
129+
128130
await this.forceStop();
129131
throw e;
130132
}

0 commit comments

Comments
 (0)