У меня есть код JavaScript селена для прокрутки до определенного веб-элемента в таблице, чтобы я мог установить флажок рядом с элементом в строке таблицы.У меня есть следующий код, который иногда работает, но иногда он не может прокрутить до элемента в таблице.
public String xapthbuyTrade = "//div[text()='gtiBuyref']";
public void scrollAndSelectTrade(String gtiBuyref) throws InterruptedException {
// WebDriverWait wait = new WebDriverWait(driver, 10);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(300000);
// wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xapthStatusCategarory)));
// visibilityOfXpathElementLocated(xapthStatusCategarory);
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", driver.findElement(By.xpath(xapthbuyTrade.replace("gtiBuyref", gtiBuyref))));
driver.findElement(By.xpath(xapthCheckBoxTrade.replace("gtiBuyref", gtiBuyref))).click();
LOGGER.info("Scroll down till the buy trade visisble");
visibilityOfCssElementLocated(cssIseUpdate);
Thread.sleep(1000);
driver.findElement(By.cssSelector(cssIseUpdate)).click();
Thread.sleep(3000);
LOGGER.info("Clicked on update button");
}
Я могу видеть элемент, присутствующий в таблице, если я прокручиваю вручную.Но когда не удается прокрутить, я получаю следующее исключение
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[text()='TSB0C590']"}
Command duration or timeout: 0 milliseconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:371)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at pages.VETCSWSearchPage.scrollAndSelectTrade(VETCSWSearchPage.java:271)
at RepairUI.RepairHelperUI.linkSellBuyInCSWPage(RepairHelperUI.java:380)
at steps.StepDefsRepairUI.linkSellBuyInCSW(StepDefsRepairUI.java:154)
at ?.Then link the sell and buy trade in International Settlements page(CosmicTre.feature:42)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[text()='TSB0C590']"}
Я попытался добавить задержку, как выделено в разделе кода. Но это не помогает.Пожалуйста, дайте мне знать, если требуется какая-либо другая информация.Я использую Firefox 52.8.0 (32-разрядная версия) и селен версия
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.9.1</version>
</dependency>