Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click on a javascript link with selenium

I generated a report through a website and I am trying to click on a link which exports the data into a csv file.

The element is:

    <span class="x21">
    <a style="color:#0000FF" href="javascript:JCRTYP('https://www.merchantconnect.com/CWRWeb/download.do?','CRCRDTYP','1','9507508464','01-FEB-2015','28-FEB-2015','14','2350','67156','WINN DIXIE 0283    S91','ALL','COMT');">
Comma Separated Value (CSV) </a>
        </span>

What I have now is to switch to the iframe and click it by the xpath. However, it throws a error "Unable to locate element". I even tried without switching to the iframe.

driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))

driver.find_element_by_xpath("html/body/table/tbody/tr[1]/td/table/tbody/tr[7]/td/span[4]/a").click()

The iframe source is:

<div class="iframes">
                <iframe style="width: 100%; height: 500px" name="FRAME1" src="/CWRWeb/nova/jsp/reports/running.jsp" align="middle" frameborder="no" height="500px" width="100%"></iframe>
                </div>

Any suggestions?

Thanks

like image 412
collarblind Avatar asked Aug 05 '26 19:08

collarblind


1 Answers

Switch to the iframe by name:

driver.switch_to.frame("FRAME1")

And locate the link by link text:

driver.find_element_by_partial_link_text("Comma Separated Value (CSV)")
like image 187
alecxe Avatar answered Aug 07 '26 07:08

alecxe