fix id selector (#573)

This commit is contained in:
LawyZheng
2024-07-10 14:55:59 +08:00
committed by GitHub
parent 2d9e74bffe
commit da66d66132
2 changed files with 5 additions and 5 deletions

View File

@@ -630,14 +630,14 @@ async function getSelect2OptionElements(element) {
while (true) {
oldOptionCount = optionList.length;
let newOptionList = document.querySelectorAll(
"#select2-drop li[role='option']",
"[id='select2-drop'] li[role='option']",
);
if (newOptionList.length === oldOptionCount) {
console.log("no more options loaded, wait 5s to query again");
// sometimes need more time to load the options, so sleep 10s and try again
await sleep(5000); // wait 5s
newOptionList = document.querySelectorAll(
"#select2-drop li[role='option']",
"[id='select2-drop'] li[role='option']",
);
console.log(newOptionList.length, " options found, after 5s");
}

View File

@@ -197,7 +197,7 @@ class SkyvernElement:
if for_id == "":
return None
locator = self.get_frame().locator(f"#{for_id}")
locator = self.get_frame().locator(f"[id='{for_id}']")
# supposed to be only one element, since id is unique in the whole DOM
if await locator.count() != 1:
return None
@@ -349,7 +349,7 @@ class Select2Dropdown(AbstractSelectDropdown):
self.frame = frame
async def __find_anchor(self, timeout: float) -> Locator:
locator = self.frame.locator("#select2-drop")
locator = self.frame.locator("[id='select2-drop']")
await locator.wait_for(state="visible", timeout=timeout)
cnt = await locator.count()
if cnt == 0:
@@ -415,7 +415,7 @@ class ComboboxDropdown(AbstractSelectDropdown):
async def __find_anchor(self, timeout: float) -> Locator:
control_id = await self.skyvern_element.get_attr("aria-controls", timeout=timeout)
locator = self.frame.locator(f"#{control_id}")
locator = self.frame.locator(f"[id='{control_id}']")
await locator.wait_for(state="visible", timeout=timeout)
cnt = await locator.count()
if cnt == 0: