Мне было поручено создать несколько автоматических тестов для веб-сайта Google Slides.Один из элементов страницы, к которому я пытаюсь получить доступ, - это выбор слайдов на левой панели.Помимо прочего, мне нужно протестировать функцию удаления слайдов, поэтому мне нужно иметь возможность выбрать конкретный слайд.Я начал с попытки щелкнуть изначально созданный.Вот как я пытаюсь его инициализировать.
@FindBy(xpath = "//*[@id=\"filmstrip\"]/div/svg")
private lateinit var slideField: WebElement
Предоставленный здесь xpath копируется непосредственно из браузера, и тот же метод отлично работает для многих других элементов.И все же моя тестовая функция падает каждый раз, когда достигает точки щелчка по этому элементу.
fun testClick(){
val wait = WebDriverWait(driver, 10)
wait.until<WebElement>(ExpectedConditions.elementToBeClickable(fileMenu))
fileMenu.click()
slideImportMenuItem.click()
pressEscKey(driver)
fileMenu.click()
createCopyMenuItem.click()
pressEscKey(driver)
slideField.click()
editMenu.click()
copyElementButton.click()
editMenu.click()
undoButton.click()
editMenu.click()
redoButton.click()
editMenu.click()
undoButton.click()
}
Обратите внимание, что, поскольку щелчок по слайду далек от первого действия, выполняемого функцией, проблема не в элементене будучи инициализированным вовремя в отличие от многих подобных проблем, которые мне удалось найти.Элемент также, кажется, не находится ни в каком отдельном кадре, который препятствовал бы его обнаружению водителемИ все же я получаю это сообщение об ошибке:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="filmstrip"]/div/svg/g"}
(Session info: chrome=75.0.3770.80)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'WINDOWS-187BSSK', ip: '172.23.40.225', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.80, chrome: {chromedriverVersion: 75.0.3770.8 (681f24ea911fe7..., userDataDir: C:\Users\Vlad\AppData\Local...}, goog:chromeOptions: {debuggerAddress: localhost:61884}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 19d219c567112fab9a909281c2a3fed9
*** Element info: {Using=xpath, value=//*[@id="filmstrip"]/div/svg/g}
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy4.click(Unknown Source)
at pages.MainPage.testClick(MainPage.kt:84)
at MainKt.main(main.kt:17)
at MainKt.main(main.kt)
Я очень новичок в Selenium и тестировании в целом, поэтому любая помощь будет оценена.
Редактировать: я попытался создать еще один слайд, а затем получить доступоба с
@FindBy(xpath = "//*[@id=\"filmstrip\"]/div/svg[1]")
private lateinit var slideField: WebElement
и
@FindBy(xpath = "//*[@id=\"filmstrip\"]/div/svg[2]")
private lateinit var slideField: WebElement
соответственно, без эффекта.