I’m trying to take all the colors of a product, but first I have to click on a button to show all the available ones. When I do it, sometimes it is successful, other times it just brings me the default color as if I had not clicked on the drop-down button. I have tried to defend waiting times without success. I’m trying to understand why this behavior is happening. I’ve tried to wait for a div (id=”tippy-5″) which is the drop-down, but it makes an error since the click is never sent correctly.
Update: If I put a breakpoint on the page.click
, and then I continue, it always throws the desired behavior. If I put the breakpoint after, it’s the opposite.
public class StockFetcher {
public static List<String> getStockFromWebPage() {
List<String> stockList = new ArrayList<>();
String productUrl = "https://articulo.mercadolibre.com.pe/MPE-653839472-tapones-loop-quiet";
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(true));
Page page = browser.newPage();
page.navigate(productUrl);
page.waitForSelector(".andes-dropdown__trigger", new Page.WaitForSelectorOptions().setTimeout(5000));
page.click(".andes-dropdown__trigger");
// page.waitForSelector("#tippy-5", new
// Page.WaitForSelectorOptions().setTimeout(5000));
List<ElementHandle> elements = page.querySelectorAll(".ui-pdp-dropdown-selector__item--label-small");
for (ElementHandle element : elements) {
String textContent = element.textContent();
stockList.add(textContent);
}
page.close();
}
return stockList;
}
}
Franco Romero is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.