I am trying to access a product but the xpath is not working at all

I am trying to access a product but the xpath is not working at all.

first I do a search for the product and when I want to access the first search item, not ”Los más populares’ and I get Message: no such element: Unable to locate element:
the site is https://inkafarma.pe
and with the search https://inkafarma.pe/buscador?keyword=pampers

I tried with switch_to.frame but I can’t figure out the logic.

at the moment my test code is like this

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 with the path to the driver executable
service = Service(executable_path='C:chromedriver_win32chromedriver.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 Inkafarma 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 for the search bar to be available
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)

# Find the <label> element with the search image and click on it
search_button = WebDriverWait(driver, 20).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "label.main-header-search-label"))
)
search_button.click()

# Wait for the results to fully load
time.sleep(10) 

# Find the first item in the list using XPath and click on it
try:
    # Scroll down the page using JavaScript
    driver.execute_script("window.scrollBy(0, 600);")
    time.sleep(10)    

    # Wait for the iframe to be present and switch context to the iframe
    # Switch to the selected iframe
    frames = driver.switch_to.frame(3)
    print("Switched to frame...")

    # Switch context back to the main content
    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)

# Close the browser
driver.switch_to.default_content()

New contributor

Neider Calderon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật