Сначала я выполняю поиск продукта, а когда хочу получить доступ к первому элементу поиска, не «Los más Populares», и я получаю Сообщение: нет такого элемента: невозможно найти элемент:
Сайт https://inkafarma.pe
и с поиском https: //inkafarma.pe/buscador?keyword=pampers
HTML-код резюме:

BOLSA 60 UN
Pañal Pampers Premium Care Talla XXG - Bolsa 60 UN
Я пробовал использовать switch_to.frame, но не могу понять логику.
На данный момент мой тестовый код выглядит следующим образом: это.
Некоторые комментарии неверны :-/
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
import time
# Set up the service
service = Service(executable_path='C:\chromedriver_win32\chromedriver.exe')
# Configure Chrome options
options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
options.add_experimental_option("prefs", prefs)
# Initialize the Chrome browser
driver = webdriver.Chrome(service=service, options=options)
# Open the page
driver.get("https://inkafarma.pe/")
time.sleep(5)
click_close_win = driver.find_element(By.XPATH, f'/html/body/div[5]/div[2]/div/mat-dialog-container/fp-home-location-contentful/div/div/div/span')
click_close_win.click()
# Wait
search_bar = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "input[id='ctrl-product-searcher']"))
)
search_bar.send_keys("Pampers")
time.sleep(2)
search_button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "label.main-header-search-label"))
)
search_button.click()
time.sleep(10)
# Find
try:
# Scroll down the page
driver.execute_script("window.scrollBy(0, 600);")
time.sleep(10)
frames = driver.switch_to.frame(3)
print("Switched to frame...")
name = driver.find_element(By.XPATH, f'/html/body/fp-root/fp-business/div/div/fp-search-landing/div[2]/fp-search-landing-desktop/div/div[2]/div[2]/fp-filtered-product-list/div/div[2]/fp-product-large/div/fp-link')
name.click()
print("First product found. Clicking on it...", name)
except Exception as e:
print("Could not find or click on the first product. Error:", e)
driver.switch_to.default_content()
Подробнее здесь: https://stackoverflow.com/questions/784 ... ing-at-all
Мобильная версия