I tried this code not working searched all resources please help. It seems like the URL redirection is handled by JavaScript without an tag or an onclick event.
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
def SCHLproject(query):
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
driver = webdriver.Chrome(options=chrome_options)
url = f"https://www.truemeds.in/search/{str(query)}"
print(driver.page)
driver.get(url)
ele = driver.find_element(By.CLASS_NAME, "sc-452fc789-2 eIXiYR")
ele.click()
print(driver.current_url)
SCHLproject("naxdom")
Indeed, the redirection URL is not specified in some DOM element in your case.
It gets fetched by JS from 'https://services.tmmumbai.in/BotService/fetchUrl?productCode=XXX' on element click.
You have to pass the code of the desired product instead of the 'XXX'.
But the product code is not specified in the DOM either.
It looks like you can extract it from the img src.
Here is the code that worked for me, but it needs to be tested on different inputs:
Please note that I've changed the locator to XPath, using classes like 'sc-452fc789-2 eIXiYR' may be tricky sometimes, as such IDs are often generated automatically by the frontend frameworks, which means they may be easily changed.
Suggested XPath also can't be called a 'reliable' locator, but it is definitely better than dynamic classes.
The provided code returns a list of endpoints for the displayed products (it doesn't include the website address itself)