![Full Screen](https://www.lambdatest.com/automation-testing-advisor/resources/images/top_arrow.svg)
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.support.events;18import org.openqa.selenium.Alert;19import org.openqa.selenium.By;20import org.openqa.selenium.OutputType;21import org.openqa.selenium.WebDriver;22import org.openqa.selenium.WebElement;23public interface WebDriverEventListener {24 /**25 * This action will be performed each time before {@link Alert#accept()}26 *27 * @param driver WebDriver28 */29 void beforeAlertAccept(WebDriver driver);30 /**31 * This action will be performed each time after {@link Alert#accept()}32 *33 * @param driver WebDriver34 */35 void afterAlertAccept(WebDriver driver);36 /**37 * This action will be performed each time before {@link Alert#dismiss()}38 *39 * @param driver WebDriver40 */41 void afterAlertDismiss(WebDriver driver);42 /**43 * This action will be performed each time after {@link Alert#dismiss()}44 *45 * @param driver WebDriver46 */47 void beforeAlertDismiss(WebDriver driver);48 /**49 * Called before {@link org.openqa.selenium.WebDriver#get get(String url)} respectively50 * {@link org.openqa.selenium.WebDriver.Navigation#to navigate().to(String url)}.51 *52 * @param url URL53 * @param driver WebDriver54 */55 void beforeNavigateTo(String url, WebDriver driver);56 /**57 * Called after {@link org.openqa.selenium.WebDriver#get get(String url)} respectively58 * {@link org.openqa.selenium.WebDriver.Navigation#to navigate().to(String url)}. Not called, if an59 * exception is thrown.60 *61 * @param url URL62 * @param driver WebDriver63 */64 void afterNavigateTo(String url, WebDriver driver);65 /**66 * Called before {@link org.openqa.selenium.WebDriver.Navigation#back navigate().back()}.67 *68 * @param driver WebDriver69 */70 void beforeNavigateBack(WebDriver driver);71 /**72 * Called after {@link org.openqa.selenium.WebDriver.Navigation navigate().back()}. Not called, if an73 * exception is thrown.74 *75 * @param driver WebDriver76 */77 void afterNavigateBack(WebDriver driver);78 /**79 * Called before {@link org.openqa.selenium.WebDriver.Navigation#forward navigate().forward()}.80 *81 * @param driver WebDriver82 */83 void beforeNavigateForward(WebDriver driver);84 /**85 * Called after {@link org.openqa.selenium.WebDriver.Navigation#forward navigate().forward()}. Not called,86 * if an exception is thrown.87 *88 * @param driver WebDriver89 */90 void afterNavigateForward(WebDriver driver);91 /**92 * Called before {@link org.openqa.selenium.WebDriver.Navigation#refresh navigate().refresh()}.93 *94 * @param driver WebDriver95 */96 void beforeNavigateRefresh(WebDriver driver);97 /**98 * Called after {@link org.openqa.selenium.WebDriver.Navigation#refresh navigate().refresh()}. Not called,99 * if an exception is thrown.100 *101 * @param driver WebDriver102 */103 void afterNavigateRefresh(WebDriver driver);104 /**105 * Called before {@link WebDriver#findElement WebDriver.findElement(...)}, or106 * {@link WebDriver#findElements WebDriver.findElements(...)}, or {@link WebElement#findElement107 * WebElement.findElement(...)}, or {@link WebElement#findElement WebElement.findElements(...)}.108 *109 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code> is called.110 * @param by locator being used111 * @param driver WebDriver112 */113 void beforeFindBy(By by, WebElement element, WebDriver driver);114 /**115 * Called after {@link WebDriver#findElement WebDriver.findElement(...)}, or116 * {@link WebDriver#findElements WebDriver.findElements(...)}, or {@link WebElement#findElement117 * WebElement.findElement(...)}, or {@link WebElement#findElement WebElement.findElements(...)}.118 *119 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code> is called.120 * @param by locator being used121 * @param driver WebDriver122 */123 void afterFindBy(By by, WebElement element, WebDriver driver);124 /**125 * Called before {@link WebElement#click WebElement.click()}.126 *127 * @param driver WebDriver128 * @param element the WebElement being used for the action129 */130 void beforeClickOn(WebElement element, WebDriver driver);131 /**132 * Called after {@link WebElement#click WebElement.click()}. Not called, if an exception is133 * thrown.134 *135 * @param driver WebDriver136 * @param element the WebElement being used for the action137 */138 void afterClickOn(WebElement element, WebDriver driver);139 /**140 * Called before {@link WebElement#clear WebElement.clear()}, {@link WebElement#sendKeys141 * WebElement.sendKeys(...)}.142 *143 * @param driver WebDriver144 * @param element the WebElement being used for the action145 */146 void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend);147 /**148 * Called after {@link WebElement#clear WebElement.clear()}, {@link WebElement#sendKeys149 * WebElement.sendKeys(...)}}. Not called, if an exception is thrown.150 *151 * @param driver WebDriver152 * @param element the WebElement being used for the action153 */154 void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend);155 /**156 * Called before {@link org.openqa.selenium.remote.RemoteWebDriver#executeScript(java.lang.String, java.lang.Object[]) }157 *158 * @param driver WebDriver159 * @param script the script to be executed160 */161 // Previously: Called before {@link WebDriver#executeScript(String)}162 // See the same issue below.163 void beforeScript(String script, WebDriver driver);164 /**165 * Called after {@link org.openqa.selenium.remote.RemoteWebDriver#executeScript(java.lang.String, java.lang.Object[]) }.166 * Not called if an exception is thrown167 *168 * @param driver WebDriver169 * @param script the script that was executed170 */171 // Previously: Called after {@link WebDriver#executeScript(String)}. Not called if an exception is thrown172 // So someone should check if this is right. There is no executeScript method173 // in WebDriver, but there is in several other places, like this one174 void afterScript(String script, WebDriver driver);175 /**176 * This action will be performed each time before {@link org.openqa.selenium.WebDriver.TargetLocator#window(java.lang.String)}177 *178 * @param driver WebDriver179 */180 void beforeSwitchToWindow(String windowName, WebDriver driver);181 /**182 * This action will be performed each time after {@link org.openqa.selenium.WebDriver.TargetLocator#window(java.lang.String)}183 *184 * @param driver WebDriver185 */186 void afterSwitchToWindow(String windowName, WebDriver driver);187 /**188 * Called whenever an exception would be thrown.189 *190 * @param driver WebDriver191 * @param throwable the exception that will be thrown192 */193 void onException(Throwable throwable, WebDriver driver);194 195 /**196 * Called before {@link org.openqa.selenium.TakesScreenshot#getScreenshotAs(OutputType)}197 * allows the implementation to determine which type of output will be generated198 *199 * @param <X> Return type for getScreenshotAs.200 * @param target target type, @see OutputType201 */202 <X> void beforeGetScreenshotAs(OutputType<X> target);203 204 /**205 * Called after {@link org.openqa.selenium.TakesScreenshot#getScreenshotAs(OutputType)}206 * allows the implementation to determine which type of output was generated207 * and to access the output itself208 *209 * @param <X> Return type for getScreenshotAs.210 * @param target target type, @see OutputType211 * @param screenshot screenshot output of the specified type212 */213 <X> void afterGetScreenshotAs(OutputType<X> target, X screenshot);214}...
![Full Screen](https://www.lambdatest.com/automation-testing-advisor/resources/images/bottom_arrow.svg)