Проблемы при загрузке файла с веб-сайта с помощью Selenium Webdriver - PullRequest
0 голосов
/ 17 июня 2019

Мне нужно загрузить 2 файла с веб-сайта, переименовать файлы в зависимости от типа отчета и переместить его в указанную папку.

enter image description here

Я попытался загрузить файл, используя xpath, но не смог этого сделать.

//*@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);

} 
}

Источник таблицы: https://www.shipper -ml.com

enter image description here

enter image description here

При выполнении кода появляется сообщение об ошибке ниже.

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)

Я верю, что яделает некоторую ошибку в предоставлении xpath.Может ли кто-нибудь помочь мне с этим.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...