-
Notifications
You must be signed in to change notification settings - Fork 1k
add native selectOptionFromDropdown
#842
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2550c0f
add native selectOptionFromDropdown
seanmcguire12 691f98f
replace combobox with select in tree
seanmcguire12 2183bf6
update prompt
seanmcguire12 f92f543
add timeout to selectOption locator
seanmcguire12 cf4b72f
add eval for os level dropdown
seanmcguire12 81d3f63
add eval for custom dropdown
seanmcguire12 ea6c044
add eval for hidden input dropdown
seanmcguire12 1a7f893
changeset
seanmcguire12 8c064dd
Update lib/handlers/handlerUtils/actHandlerUtils.ts
miguelg719 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@browserbasehq/stagehand": patch | ||
--- | ||
|
||
improved handling for OS level dropdowns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const custom_dropdown: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
/** | ||
* This eval is meant to test whether we do not incorrectly attempt | ||
* the selectOptionFromDropdown method (defined in actHandlerUtils.ts) on a | ||
* 'dropdown' that is not a <select> element. | ||
* | ||
* This kind of dropdown must be clicked to be expanded before being interacted | ||
* with. | ||
*/ | ||
|
||
try { | ||
const page = stagehand.page; | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/expand-dropdown/", | ||
); | ||
|
||
await page.act("click the 'Select a Country' dropdown"); | ||
|
||
// we are expecting stagehand to click the dropdown to expand it, | ||
// and therefore the available options should now be contained in the full | ||
// a11y tree. | ||
|
||
// to test, we'll grab the full a11y tree, and make sure it contains 'Canada' | ||
const extraction = await page.extract(); | ||
const fullTree = extraction.page_text; | ||
|
||
if (fullTree.includes("Canada")) { | ||
return { | ||
_success: true, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
message: "unable to expand the dropdown", | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error attempting to select an option from the dropdown: ${error.message}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const hidden_input_dropdown: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
/** | ||
* This eval is meant to test whether we do not incorrectly attempt | ||
* the selectOptionFromDropdown method (defined in actHandlerUtils.ts) on a | ||
* hidden input 'dropdown'. | ||
* | ||
* This kind of dropdown must be clicked to be expanded before being interacted | ||
* with. | ||
*/ | ||
|
||
try { | ||
const page = stagehand.page; | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/hidden-input-dropdown/", | ||
); | ||
|
||
await page.act("click to expand the 'Favourite Colour' dropdown"); | ||
|
||
// we are expecting stagehand to click the dropdown to expand it, | ||
// and therefore the available options should now be contained in the full | ||
// a11y tree. | ||
|
||
// to test, we'll grab the full a11y tree, and make sure it contains 'Green' | ||
const extraction = await page.extract(); | ||
const fullTree = extraction.page_text; | ||
|
||
if (fullTree.includes("Green")) { | ||
return { | ||
_success: true, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
message: "unable to expand the dropdown", | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error attempting click to expand the dropdown: ${error.message}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
|
||
export const os_dropdown: EvalFunction = async ({ | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
logger, | ||
}) => { | ||
/** | ||
* This eval is meant to test whether we can correctly select an element | ||
* from an OS level dropdown | ||
*/ | ||
|
||
try { | ||
const page = stagehand.page; | ||
await page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/nested-dropdown/", | ||
); | ||
|
||
await page.act( | ||
"choose 'Smog Check Technician' from the 'License Type' dropdown", | ||
); | ||
const selectedOption = await page | ||
.locator( | ||
"xpath=/html/body/form/div[1]/div[3]/article/div[2]/div[1]/select[2] >> option:checked", | ||
) | ||
.textContent(); | ||
|
||
if (selectedOption === "Smog Check Technician") { | ||
return { | ||
_success: true, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
message: "incorrect option selected from the dropdown", | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
return { | ||
_success: false, | ||
message: `error attempting to select an option from the dropdown: ${error.message}`, | ||
seanmcguire12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} finally { | ||
await stagehand.close(); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.