|
@@ -112,8 +112,8 @@ async function findTrigger(page: Page, label: string, expectedValue: string) {
|
|
|
// 这种情况处理: <generic>标签文本</generic><combobox role="combobox">
|
|
// 这种情况处理: <generic>标签文本</generic><combobox role="combobox">
|
|
|
console.debug(`选择器策略4: 尝试相邻 combobox 查找`);
|
|
console.debug(`选择器策略4: 尝试相邻 combobox 查找`);
|
|
|
try {
|
|
try {
|
|
|
- // 找到包含标签文本的元素
|
|
|
|
|
- const labelElement = page.locator(`text="${label}"`).first();
|
|
|
|
|
|
|
+ // 使用 getByText 而不是 text= 选择器,更可靠地处理特殊字符
|
|
|
|
|
+ const labelElement = page.getByText(label, { exact: true }).first();
|
|
|
const labelCount = await labelElement.count();
|
|
const labelCount = await labelElement.count();
|
|
|
console.debug(`选择器策略4: 找到 ${labelCount} 个包含文本 "${label}" 的元素`);
|
|
console.debug(`选择器策略4: 找到 ${labelCount} 个包含文本 "${label}" 的元素`);
|
|
|
if (labelCount > 0) {
|
|
if (labelCount > 0) {
|
|
@@ -123,6 +123,7 @@ async function findTrigger(page: Page, label: string, expectedValue: string) {
|
|
|
const comboboxCount = await combobox.count();
|
|
const comboboxCount = await combobox.count();
|
|
|
console.debug(`选择器策略4: 找到 ${comboboxCount} 个相邻的 combobox`);
|
|
console.debug(`选择器策略4: 找到 ${comboboxCount} 个相邻的 combobox`);
|
|
|
if (comboboxCount > 0) {
|
|
if (comboboxCount > 0) {
|
|
|
|
|
+ // 确保元素可见后再返回
|
|
|
await combobox.waitFor({ state: "visible", timeout: 2000 });
|
|
await combobox.waitFor({ state: "visible", timeout: 2000 });
|
|
|
console.debug(`选择器策略4成功: 找到相邻 combobox "${label}"`);
|
|
console.debug(`选择器策略4成功: 找到相邻 combobox "${label}"`);
|
|
|
return combobox;
|
|
return combobox;
|
|
@@ -132,6 +133,33 @@ async function findTrigger(page: Page, label: string, expectedValue: string) {
|
|
|
console.debug(`选择器策略4失败: 相邻 combobox 查找`, err);
|
|
console.debug(`选择器策略4失败: 相邻 combobox 查找`, err);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 策略 5: 处理标签和 * 分离的情况(如:城市 * 是两个元素)
|
|
|
|
|
+ // 查找包含标签文本的父元素,然后在父元素的兄弟中查找 combobox
|
|
|
|
|
+ console.debug(`选择器策略5: 尝试处理标签和 * 分离的情况`);
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 先找所有包含标签文本的元素(不要求 exact)
|
|
|
|
|
+ const labelElementLocator = page.getByText(label).first();
|
|
|
|
|
+ const labelCount = await labelElementLocator.count();
|
|
|
|
|
+ console.debug(`选择器策略5: 找到 ${labelCount} 个包含文本 "${label}" 的元素(非精确匹配)`);
|
|
|
|
|
+ if (labelCount > 0) {
|
|
|
|
|
+ // 获取第一个匹配元素的父元素
|
|
|
|
|
+ const parent = labelElementLocator.locator("..");
|
|
|
|
|
+ // 在父元素的兄弟元素中查找 combobox(向上两层)
|
|
|
|
|
+ const grandParent = parent.locator("..");
|
|
|
|
|
+ const combobox = grandParent.locator('[role="combobox"]').first();
|
|
|
|
|
+ const comboboxCount = await combobox.count();
|
|
|
|
|
+ console.debug(`选择器策略5: 找到 ${comboboxCount} 个 combobox`);
|
|
|
|
|
+ if (comboboxCount > 0) {
|
|
|
|
|
+ await combobox.waitFor({ state: "visible", timeout: 2000 });
|
|
|
|
|
+ console.debug(`选择器策略5成功: 找到 combobox "${label}"`);
|
|
|
|
|
+ return combobox;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ console.debug(`选择器策略5: 未找到匹配的 combobox`);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ console.debug(`选择器策略5失败:`, err);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 所有策略都失败
|
|
// 所有策略都失败
|
|
|
throwError({
|
|
throwError({
|
|
|
operation: "selectRadixOption",
|
|
operation: "selectRadixOption",
|