0

I want to click behind this link for this image:

want to click behind this link for this image

HTML:

<img src="../images/qi_images/retaileranalytics/Export_XLSX_Normal.png" style="width:32px;height:32px;" onclick="mstrmojo.dom.captureDomEvent('*lK36*kW9AD865CF3BF94D709C845EC84C9867B7*x1*t1659566066908','click', self, event)">

I tried to use:

driver.find_element(By.XPATH, "/html/body/div[2]/div[3]/div/div[2]/div/div[1]/div[2]/div[3]/div/div/div/div/div[10]/div[1]/img").click() 

but does not work please help.

If you right click it you will see a hyperlink popup:

If you right click it you will see a hyperlink popup

Here is the HTML:

<div mstridx="0" class="mstrmojo-ListBox-item mstrmojo-InteractiveText" style="undefined">Hyperlink1</div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Mustard
  • 33
  • 1
  • 5
  • Thanks for answering. Yeah, I can click on the URL but just can't get the Selenium to click on it. The link will basically take you to a different tab to download. – Mustard Aug 03 '22 at 22:56

1 Answers1

0

The desired element is a dynamic element, so to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img[src*='Export_XLSX_Normal'][onclick*='captureDomEvent']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[contains(@src, 'Export_XLSX_Normal') and contains(@onclick, 'captureDomEvent')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for answering. It didn't work for me. I am getting the timeout exception: TimeoutException(message, screen, stacktrace). If I go without wait, it's the unable to find element message: Message: no such element: Unable to locate element: – Mustard Aug 04 '22 at 03:00
  • @Mustard From my experience try using CSS_SELECTOR instead of XPATH. Also can try right click>inspect element>copy JSPATH then do driver.execute_script('return document.querySelector('PATH')') (https://selenium-python.readthedocs.io/api.html) – Crunchy Aug 04 '22 at 03:10