-
Notifications
You must be signed in to change notification settings - Fork 93
added clear method in server file #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -221,6 +221,31 @@ server.tool( | |||||||||||||
| } | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| server.tool( | ||||||||||||||
| "clear", | ||||||||||||||
| "resets content of the element", | ||||||||||||||
| { | ||||||||||||||
| ...locatorSchema, | ||||||||||||||
| text: z.string().describe("Resets content of the element") | ||||||||||||||
| }, | ||||||||||||||
| async ({ by, value, text, timeout = 10000 }) => { | ||||||||||||||
| try { | ||||||||||||||
| const driver = getDriver(); | ||||||||||||||
| const locator = getLocator(by, value); | ||||||||||||||
| const element = await driver.wait(until.elementLocated(locator), timeout); | ||||||||||||||
| await element.clear(); | ||||||||||||||
|
Comment on lines
+235
to
+236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Wait for element to be visible and enabled before clearing. elementLocated only ensures presence in the DOM; clear() can fail on hidden/disabled elements. Guard with visibility/enabled waits for robustness. - const element = await driver.wait(until.elementLocated(locator), timeout);
- await element.clear();
+ const element = await driver.wait(until.elementLocated(locator), timeout);
+ await driver.wait(until.elementIsVisible(element), timeout);
+ await driver.wait(until.elementIsEnabled(element), timeout);
+ await element.clear();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| return { | ||||||||||||||
| content: [{ type: 'text', text: 'Element value reset' }] | ||||||||||||||
| }; | ||||||||||||||
| } catch (e) { | ||||||||||||||
| return { | ||||||||||||||
| content: [{ type: 'text', text: `Error in reset of the element: ${e.message}` }] | ||||||||||||||
| }; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| server.tool( | ||||||||||||||
| "get_element_text", | ||||||||||||||
| "gets the text() of an element", | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove unused required "text" input and param from the clear tool.
The tool ignores the provided "text" but still requires it via zod, forcing clients to supply meaningless data and creating API friction.
Apply this diff to drop the unused field and param:
server.tool( "clear", "resets content of the element", { - ...locatorSchema, - text: z.string().describe("Resets content of the element") + ...locatorSchema }, - async ({ by, value, text, timeout = 10000 }) => { + async ({ by, value, timeout = 10000 }) => {📝 Committable suggestion
🤖 Prompt for AI Agents