0

I have to download 2 files from a website and rename the files based on the report type and move it to the specific folder.

enter image description here

I tried downloading the file using xpath but unable to do so.

//*@id="ctrl1805929160"]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[10]/td[1]

public static void execute(WebDriver wd) throws Throwable{
wd.get("https://www.shipper-ml.com/viewReports.do");  
Thread.sleep(2000);
List<WebElement> list= wd.findElements(By.xpath("//table[@class='lcb']/tbody/tr/td/table[@class='ibody']/tbody/tr/td[contains(translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),06)]/parent::tr/td[10]/a"));
int i = 0;
FileUtils.cleanDirectory(new File("C:\\Users\\NEA558\\Desktop\\New_Folder\\Files"));
for (WebElement element:list)
{
    i++;
    element.click();
    Thread.sleep(1000);
    System.out.println((element.findElement(By.xpath("(//table[@class='lcb']/tbody/tr/td/table[@class='ibody']/tbody/tr/td[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),06)]/parent::tr/td[10])["+i+"]")).getText()).substring(0,3));
    String report_type = (element.findElement(By.xpath("(//table[@class='lcb']/tbody/tr/td/table[@class='ibody']/tbody/tr/td[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),06)]/parent::tr/td[10])["+i+"]")).getText()).substring(0,3);

} 
}

Table source : https://www.shipper-ml.com

enter image description here

enter image description here

I am getting below error message when I am executing the code.

Element info: {Using=xpath, value=//table[@class='lcb']/tbody/tr/td/table[@class='ibody']/tbody/tr/td[contains(translate(text(),'0123456789'),'06')]/parent::tr/td[1]/a}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:437)
at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:513)
at org.openqa.selenium.By$ByXPath.findElements(By.java:356)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:398)
at package1.Test_new.execute(Test_new.java:80)
at package1.Test_new.main(Test_new.java:105)

I believe I am doing some mistake in giving the xpath. Can somebody help me with that.

Begginer
  • 317
  • 2
  • 3
  • 13
  • Can you post your code & table source? Are you trying to click on the table row? – Sureshmani Kalirajan Jun 17 '19 at 15:27
  • Hi @Sureshmani, I have updated the question with the code and also the table source. Any help from you will be highly appreciated as I need to fix this asap. – Begginer Jun 17 '19 at 15:41
  • What browser are you using? Each browser will have different limitations for downloads and need to be handled differently in the code. Also, your table source links to a page behind a login wall. Use `driver.PageSource` to get the html and add it as a gist (github text file), or something else, to this question. Also, what file extension are the excel docs? – Asyranok Jun 17 '19 at 16:25
  • Possible duplicate of [How to download any file and save it to the desired location using Selenium Webdriver](https://stackoverflow.com/questions/16746707/how-to-download-any-file-and-save-it-to-the-desired-location-using-selenium-webd) – stiemannkj1 Jun 17 '19 at 17:22
  • Are you able to resolve this issue? Can you please update post with html of the table? The link that you provided in OP is forcing for the login to shipper. – supputuri Jun 17 '19 at 20:10
  • I need to automate the process wherein it should automatically download the required file from the website – Begginer Jun 18 '19 at 07:28
  • @supputuri, I have updated the post with html of the table. – Begginer Jun 18 '19 at 07:49
  • @Asyranok, file extension is .csv and I am using Chrome browser. I have attached the html part in the question. – Begginer Jun 18 '19 at 10:20
  • Sorry, I missed this thread. Are you still looking for the help on this issue? – supputuri Jul 07 '19 at 03:44
  • No, I resolved it.. Thanks for the reply, but... – Begginer Jul 29 '19 at 15:10

0 Answers0