I need to download the CSV files from this page but i am not able to do so. PFA the screenshot of the page from where the files has to be downloaded :

enter image description here

enter image description here

I have tried the below code but it doesn't work

JavascriptExecutor js = (JavascriptExecutor) wd;          

  • 1
    the screenshot is very nice, however a HTML snippet would be much more useful.
    – user34705
    Commented Nov 28, 2018 at 9:41
  • Hi Dan, Thanks for the prompt response. I have uploaded the scrennshot of HTML snippet.
    – Novice
    Commented Nov 28, 2018 at 9:48
  • By.xpath("//*[@id='ctrl2016284712']/, this id must be dynamic in nature thats why your are unable to click, one way to know weather it is dynamic load twice and check id value Commented Nov 28, 2018 at 9:58
  • Yes it is dynamic in nature. So how should i go ahead ?
    – Novice
    Commented Nov 28, 2018 at 10:10
  • @Novice go with creating dynamic Xpath with contains Commented Nov 28, 2018 at 12:06

3 Answers 3


I guess you could get the 'href' attribute from the anchor tag and just append your base url to it. Then do driver.get(baseURL + href). Also if you face any difficulty creating an xpath then do let me know, I will explain it more in detail.

Updated answer: Try this xpath since you want to download only csv type of file: //table[@class='lcb']/tbody/tr/td/table[@class='ibody']/tbody/tr/td[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'csv')]/parent::tr/td[7]

  • wd.get("shipper-ml.com/…); I gave this but no success. I am getting "HTTP Status 500 – Internal Server Error" error.
    – Novice
    Commented Nov 29, 2018 at 6:07
  • Can you help me ? It would be very great. I am stuck on this from a long time.
    – Novice
    Commented Nov 29, 2018 at 6:08
  • Is it possible to share the url on PM? I could have a look Commented Nov 29, 2018 at 6:09
  • Yes. Can you give me your mail id ?
    – Novice
    Commented Nov 29, 2018 at 6:12
  • Try this xpath: //table[@class='ibody']/tbody/tr[24]/td[7]/a . Let me know if that works Commented Nov 29, 2018 at 6:14

I would not go from the structure in your case but rather from a content. Here is the example of html:

        <table class="table table-condensed">
                    <td>28/11/2018 09:13</td>
                        <a hef="asdfsdf">

and here is the example of xpath:

//tbody/tr[./td[text()='28112706.CSV']|./td[text()='28/11/2018 09:13']]/td/a

that returns a element that resides in the table row where we have the cell with 28112706.CSV AND the cell with 28112706.CSV

So your challenge is to define the row you want to use and describe the conditionss for the content in xPath expression.

  • Hi Alexey, it's a third party website so I cannot make changes in that. And also the id's are generated dynamically so how to handle that ?
    – Novice
    Commented Nov 28, 2018 at 10:40
  • @Novice did I mention any changes to the website? I just described how you should build your xpath to define the row you d like to operate with to download file. You should refer to the content, not to the structure.
    – Alexey R.
    Commented Nov 28, 2018 at 10:41
  • I am not sure how to do it. Can you help me ?
    – Novice
    Commented Nov 29, 2018 at 5:21

If you are looking at downloading all the CSV files, you may want to use findElements() to get all the links and click each one. Looking at the image and HTML snippet, looks like you have a single link in each row pointing to the CSV file.

List<WebElement> allLinks = wd.findElements(By.cssSelector("tr a"));

Should return all the links. Now you can loop through the list and click on each element. Something like:

for(WebElement e: allLinks)
  • Hi Dakshinamurthy, Actually I am not able to point to table because as per my understanding first I should be able to point to table and then only I should go for downloading the files. Isn't it ? wd.findElement(By.xpath("//*[@id='ctrl1857714716']/tbody/tr/td/table/tbody/tr/td/table")); I tried this but no success.
    – Novice
    Commented Nov 29, 2018 at 5:19
  • You do not need to descend from the table onwards. The above selector should give you all links in each of the row. Commented Nov 29, 2018 at 6:06
  • Couple of points. 1. Prefer CSS selectors to XPath. 2. Have a look at developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/… for a quick introduction to CSS selectors. Commented Nov 29, 2018 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.