Fix select answer mismatch: validate answer against available options
Built-in answerFor() could return a number (e.g. "7" for years experience) when the select only has Yes/No options, causing selectOptionFuzzy to fail silently. Now checks if the answer matches any available option before using it, falling through to AI with actual options if not. Also added "right to work" to work authorization pattern matching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,7 @@ export class FormFiller {
|
||||
// Work auth
|
||||
if (l.includes('sponsor') || l.includes('visa')) return p.work_authorization?.requires_sponsorship ? 'Yes' : 'No';
|
||||
if (l.includes('relocat')) return p.willing_to_relocate ? 'Yes' : 'No';
|
||||
if (l.includes('authorized') || l.includes('eligible') || l.includes('legally') || l.includes('work in the u')) {
|
||||
if (l.includes('authorized') || l.includes('eligible') || l.includes('legally') || l.includes('work in the u') || l.includes('right to work')) {
|
||||
return p.work_authorization?.authorized ? 'Yes' : 'No';
|
||||
}
|
||||
if (l.includes('remote') && (l.includes('willing') || l.includes('comfortable') || l.includes('able to'))) return 'Yes';
|
||||
@@ -493,7 +493,17 @@ Answer:`;
|
||||
const existing = await sel.inputValue().catch(() => '');
|
||||
// "Select an option" is LinkedIn's placeholder — treat as unfilled
|
||||
if (existing && !/^select an? /i.test(existing)) continue;
|
||||
// Get available options for validation
|
||||
const availOpts = await sel.$$eval('option', els =>
|
||||
els.map(el => el.textContent?.trim()).filter(t => t && !/^select/i.test(t))
|
||||
).catch(() => []);
|
||||
let answer = this.answerFor(lbl);
|
||||
// If built-in answer doesn't match any option (e.g. got "7" but options are Yes/No), discard it
|
||||
if (answer && availOpts.length > 0) {
|
||||
const ansLower = answer.toLowerCase();
|
||||
const matches = availOpts.some(o => o.toLowerCase() === ansLower || o.toLowerCase().includes(ansLower) || ansLower.includes(o.toLowerCase()));
|
||||
if (!matches) answer = null;
|
||||
}
|
||||
if (!answer) {
|
||||
// EEO/voluntary fields — default to "Prefer not to disclose"
|
||||
const ll = lbl.toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user