Skip to content

Commit

Permalink
catch edge case of no object id for query selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ebebbington committed May 2, 2024
1 parent 30fc43c commit e6f7db9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class Element {
/**
* ObjectId belonging to this element
*/
readonly #objectId: string;

readonly #node: ProtocolTypes.DOM.Node;

/**
Expand All @@ -43,8 +45,10 @@ export class Element {
selector: string,
page: Page,
node: ProtocolTypes.DOM.Node,
objectId: string,
) {
this.#node = node;
this.#objectId = objectId;
this.#page = page;
this.#selector = selector;
}
Expand Down Expand Up @@ -108,7 +112,7 @@ export class Element {
"DOM.setFileInputFiles",
{
files: files,
nodeId: this.#node.nodeId,
objectId: this.#objectId,
backendNodeId: this.#node.backendNodeId,
},
);
Expand Down Expand Up @@ -210,7 +214,7 @@ export class Element {
ProtocolTypes.DOM.GetContentQuadsRequest,
ProtocolTypes.DOM.GetContentQuadsResponse
>("DOM.getContentQuads", {
nodeId: this.#node.nodeId,
objectId: this.#objectId,
});
const layoutMetrics = await this.#page.send<
null,
Expand Down
7 changes: 7 additions & 0 deletions src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,23 @@ export class Page extends ProtocolClass {
'The selector "' + selector + '" does not exist inside the DOM',
);
}

if (!result.result.objectId) {
await this.client.close("Unable to find the object");
}

const { node } = await this.send<
ProtocolTypes.DOM.DescribeNodeRequest,
ProtocolTypes.DOM.DescribeNodeResponse
>("DOM.describeNode", {
objectId: result.result.objectId,
});

return new Element(
selector,
this,
node,
result.result.objectId as string,
);
}

Expand Down
6 changes: 0 additions & 6 deletions tests/unit/element_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ const serverAdd = `http://${
}:1447`;
Deno.test("element_test.ts", async (t) => {
await t.step("click()", async (t) => {
await t.step(
"Can handle things like downloads opening new tab then closing",
async () => {
},
);

await t.step(
"It should allow clicking of elements and update location",
async () => {
Expand Down

0 comments on commit e6f7db9

Please sign in to comment.