У меня есть кнопка «Просмотр PDF», и когда я нажимаю, она открывает другое новое окно браузера как средство просмотра PDF, и я перехожу ко второму окну. Здесь я пытаюсь проверить, отображается ли какое-либо содержимое PDF на этой странице. Мне не нужно проверять какой-либо текст в формате PDF, но мне просто нужно проверить, доступно ли какое-то содержимое. Здесь я пытаюсь проверить наличие тега div (с идентификатором), который отображается в окне браузера, и по какой-то причине он не идентифицирует этот элемент. Пожалуйста, помогите мне с тем, что не так с моим кодом. Любое другое предложение или решение для проверки было бы полезно здесь.
Title of the browser is : Application V5 - PDF Viewer
URL of the browser is : https://sample.com/preferences/pdfviewer.jsp
соответствующий html код
<div id="content">
<embed id="plugin" type="application/x-google-chrome-pdf" src="https://sample.com/servlet/pdfviewer" stream-url="chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/23576f4e-363a-4f60-a63a-b770beb66c41" headers="Cache-Control: private
Connection: Keep-Alive
Content-Disposition: inline; filename=image.pdf
Content-Length: 23721
Content-Type: application/pdf
Date: Thu, 09 Jan 2020 18:53:13 GMT
Expires: Thu, 09 Jan 2020 18:53:18 GMT
Keep-Alive: timeout=5, max=98
Server: Apache
" background-color="0xFF525659" top-toolbar-height="56" javascript="allow" top-level-url="undefined">
</div>
Мой сценарий имеет
WebElement pdfViewButton = browser.findElement(By.id("frmResults:btnPdfView"));
pdfViewButton.click();
WebDriverWait wait = new WebDriverWait(browser, 60);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> AllWindowHandles = browser.getWindowHandles();
String window1 = (String) AllWindowHandles.toArray()[0];
scenario.write("Currently in Parent Window = " + AllWindowHandles.toArray()[0]);
scenario.write(browser.getCurrentUrl());
scenario.write(browser.getTitle());
scenario.write(String.valueOf(AllWindowHandles.size()));
String window2 = (String) AllWindowHandles.toArray()[1];
scenario.write("Switching to Child (Viewer) window = " + AllWindowHandles.toArray()[1]);
browser.switchTo().window(window2);
scenario.write(browser.getCurrentUrl());
scenario.write(browser.getTitle());
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("content")));
Screenshot.takeScreenshot(BaseSteps.scenario, browser);
WebElement pdfViewer = browser.findElement(By.id("content"));
assertThat(pdfViewer.isDisplayed())
.overridingErrorMessage("The pdf viewer window is launched, but there is no content is displayed.")
.isTrue();
browser.switchTo().window(window2).close();
здесь это ошибка ... (ошибка появляется в строке "wait.until" ....
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.id: content (tried for 60 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at Utilities.Common.viewTheContentsWithPDFViewer(Common.java:268)
at Steps.Steps.Verify_the_pdfviewer_is_launching_with_data_content_for_that_item(Steps.java:157)
at ✽.And Verify the pdfviewer is launching with data content for that item(Returns.feature:19)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#content"}
(Session info: chrome=78.0.3904.87)