День добрый,
решил вот попробовать Html Elements(версия 1.19). Хедер на главной странице оформил в виде блока и
если локаторы написаны правильно, то все работает без проблем, но вот когда xPath блока неправильный (на странице нет елемента с таким xPath, например xpath=“some_not_existing_xpath”), то поиск такого елемента продолжается от 1 до 10 минут и только потом сваливается с NoSuchElementException (при этом в стек-трейсе указано: Timed out after 5 seconds), тогда как я ожидаю увидеть этот exception через 5 секунд после начала поиска
В консоли selenium-grid видно, что на протяжении этих 10 минут многократно появляется строчка: 09:35:17.240 INFO - Executing: [find element: By.xpath: some_not_existing_xpath])
Вопрос: как можно избавиться от такого длительного таймаута?
Вот внешний блок:
public class Header extends HtmlElement {
@FindBy(xpath = ".//div[@class='header'].//a[2]")
private Button searchButton;
public SearchPage clickSearchButton() {
searchButton.click();
return pageManager.searchPage;
}
}
Вот так блок используется на странице:
public class InternalPage extends Page {
public InternalPage(PageManager pageManager) {
super(pageManager);
}
@Getter
@FindBy(xpath = "some_not_existing_xpath")
private Header header;
public boolean isLoggedIn() {
return pageManager.internalPage.waitForPageLoaded();
}
@Override
public InternalPage ensurePageLoaded() {
super.ensurePageLoaded();
wait.until(presenceOfElementLocated(By.xpath("//div[@class='header']")));
return this;
}
}
Инициализация страниц:
public class PageManager {
@Getter
private WebDriver driver;
public HomePage homePage;
public LoginPage loginPage;
public InternalPage internalPage;
public SearchPage searchPage;
public BookingPage bookingPage;
public HotelPage hotelPage;
public ReservationsPage reservationsPage;
public ResetPasswordPage resetPasswordPage;
public SearchResultsPage searchResultsPage;
public PageManager(WebDriver driver) {
this.driver = driver;
homePage = initElements(new HomePage(this));
loginPage = initElements(new LoginPage(this));
internalPage = initElements(new InternalPage(this));
searchPage = initElements(new SearchPage(this));
bookingPage = initElements(new BookingPage(this));
hotelPage = initElements(new HotelPage(this));
reservationsPage = initElements(new ReservationsPage(this));
resetPasswordPage = initElements(new ResetPasswordPage(this));
searchResultsPage = initElements(new SearchResultsPage(this));
}
private <T extends Page> T initElements(T page) {
PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), page);
return page;
}
}
А это метод в котором и валится Exception:
SearchPage openSearchPage() {
return pageManager.internalPage
.getHeader()
.clickSearchButton();
}
Код ошибки:
org.openqa.selenium.NoSuchElementException: Timed out after 5 seconds. Unable to locate the element
at org.openqa.selenium.support.pagefactory.AjaxElementLocator.findElement(AjaxElementLocator.java:90)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at ru.yandex.qatools.htmlelements.loader.decorator.proxyhandlers.WebElementNamedProxyHandler.invoke(WebElementNamedProxyHandler.java:44)
at com.sun.proxy.$Proxy28.click(Unknown Source)
at ru.yandex.qatools.htmlelements.element.TypifiedElement.click(TypifiedElement.java:112)
at ui.pages.elements.internal_page.NavigationMenu.clickSearchButton(NavigationMenu.java:34)
at ui.app_logic.NavigationHelper.openSearchPage(NavigationHelper.java:35)
at ui.app_logic.SearchHelper.searchOffersIn(SearchHelper.java:18)
at ui.app_logic.ReservationHelper.bookRandomOffer(ReservationHelper.java:24)
at ui_test.MainTest.makeBooking(MainTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.runSuites(TestNG.java:1028)
at org.testng.TestNG.run(TestNG.java:996)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: org.openqa.selenium.NoSuchElementException: Timed out after 5 seconds. Unable to locate the element
at org.openqa.selenium.support.pagefactory.AjaxElementLocator.findElement(AjaxElementLocator.java:90)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at ru.yandex.qatools.htmlelements.loader.decorator.proxyhandlers.WebElementNamedProxyHandler.invoke(WebElementNamedProxyHandler.java:44)
at com.sun.proxy.$Proxy28.findElement(Unknown Source)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.AjaxElementLocator.access$001(AjaxElementLocator.java:40)
at org.openqa.selenium.support.pagefactory.AjaxElementLocator$SlowLoadingElement.isLoaded(AjaxElementLocator.java:156)
at org.openqa.selenium.support.ui.SlowLoadableComponent.get(SlowLoadableComponent.java:69)
at org.openqa.selenium.support.pagefactory.AjaxElementLocator.findElement(AjaxElementLocator.java:86)
... 33 more
Caused by: org.openqa.selenium.NoSuchElementException: Timed out after 5 seconds. Unable to locate the element
at org.openqa.selenium.support.pagefactory.AjaxElementLocator.findElement(AjaxElementLocator.java:90)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at ru.yandex.qatools.htmlelements.loader.decorator.proxyhandlers.WebElementNamedProxyHandler.invoke(WebElementNamedProxyHandler.java:44)
at com.sun.proxy.$Proxy28.findElement(Unknown Source)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.AjaxElementLocator.access$001(AjaxElementLocator.java:40)
at org.openqa.selenium.support.pagefactory.AjaxElementLocator$SlowLoadingElement.isLoaded(AjaxElementLocator.java:156)
at org.openqa.selenium.support.ui.SlowLoadableComponent.get(SlowLoadableComponent.java:69)
at org.openqa.selenium.support.pagefactory.AjaxElementLocator.findElement(AjaxElementLocator.java:86)
... 41 more
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"some_not_existing_xpath"}
(Session info: chrome=65.0.3325.181)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.03 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'IEVL566', ip: '10.65.147.16', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7), userDataDir=C:\Users\diadura\AppData\Local\Temp\scoped_dir19432_29083}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=65.0.3325.181, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: e892ddcdfe119649f2d6f81e90921feb
*** Element info: {Using=xpath, value=some_not_existing_xpath}