-1

I am now convinced that there is no solution to this. But in case there is someone out there who can help: Whole Element that I want to click on genesys cloud is (Its a part of a table):

<a target="_blank" data-bind="
                    attr: {
                        href: lastReportRun().reportUrl
                    },
                    lAttr: {
                        title: 'reports.list.grid.downloadColumn.fileTypes.' + lastReportFileType()
                    },
                    lString: 'reports.list.grid.downloadColumn.fileTypes.' + lastReportFileType()
                " href="https://apps.usw2.pure.cloud/platform/api/v2/downloads/9161911a0307202a" title="XLSX">XLSX</a>

Element snapshot:

enter image description here

I am trying to locate this element to click on it and start downloading the .xlsx file. These are the things I have tried so far, but no luck. Can someone please help me understand where I can correct it.

Code trials:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "XLSX"))).click()

driver.find_element_by_link_text("XLSX").click()

driver.find_element_by_xpath(u'//a[text()="XLSX"]').click()

driver.find_element_by_xpath('//a[normalize-space(text())="XLSX').click()

driver.find_element(By.XPATH, "//input[@name='XLSX' and @value='XLSX']").click()

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//*input[@name='XLSX' and @value='XLSX']"))).click()

driver.find_element_by_xpath('/html/body/div[1]/div/div/div/div/div/div/div/div/div[2]/div[2]/div/div[5]/a').click()

WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//*span[contains(., 'XLSX')]"))).click()

l=driver.find_element_by_xpath("//*a[@title='XLSX']")
l.click()
RCN
  • 101
  • 10
  • 1
    The link is probably in iframe – JaSON Apr 27 '22 at 14:11
  • better show real url for this HTML so we could see full HTML and test code on real HTML. – furas Apr 27 '22 at 16:12
  • @JaSON Yes, looks like it. I tried WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_xpath, still didnt work – RCN Apr 28 '22 at 10:07
  • You should pass exact locator of iframe into `frame_to_be_available_and_switch_to_it` as argument – JaSON Apr 28 '22 at 11:09

1 Answers1

0

The desired element is a dynamic <a> 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 LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "XLSX"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href^='https://apps.usw2'][title='XLSX'][data-bind]"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[starts-with(@href, 'https://apps.usw2') and text()='XLSX'][@title='XLSX' and @data-bind]"))).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
  • Thank You for your reply. I tried these, but these are giving me timeout exception, I have also tried adjusting the wait time, still... – RCN Apr 28 '22 at 03:27