Created
March 20, 2024 11:10
-
-
Save SarahElson/bb979915cb18e1549736a95ae77ba247 to your computer and use it in GitHub Desktop.
How to Handle Modal Dialog Box in Selenium WebDriver Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test; | |
| import java.net.*; | |
| import java.time.Duration; | |
| import java.util.HashMap; | |
| import org.openqa.selenium.remote.RemoteWebDriver; | |
| import org.openqa.selenium.support.ui.WebDriverWait; | |
| import org.openqa.selenium.chrome.ChromeOptions; | |
| import org.testng.annotations.*; | |
| public class BaseTest | |
| { | |
| public RemoteWebDriver driver = null; | |
| public WebDriverWait wait; | |
| String username = System.getenv("LT_USERNAME") == null ? "<lambdatest_username>" : System.getenv("LT_USERNAME"); | |
| String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "<lambdatest_accesskey>" : System.getenv("LT_ACCESS"); | |
| @BeforeTest | |
| public void setup() { | |
| try { | |
| ChromeOptions chromeOptions = new ChromeOptions(); | |
| chromeOptions.setPlatformName("Windows 10"); | |
| chromeOptions.setBrowserVersion("122.0"); | |
| HashMap<String, Object> ltOptions = new HashMap<String, Object>(); | |
| ltOptions.put("build", "Handling Dialog Box Selenium Java"); | |
| ltOptions.put("name", "Handling Dialog Box Selenium Java"); | |
| ltOptions.put("w3c", true); | |
| chromeOptions.setCapability("LT:Options", ltOptions); | |
| driver = new RemoteWebDriver( | |
| new URL("https://" + username + ":" + accessKey + "@hub.lambdatest.com/wd/hub"), chromeOptions); | |
| //to set default explicit wait duration as 20 seconds | |
| wait = new WebDriverWait(driver, Duration.ofSeconds(20)); | |
| } catch (MalformedURLException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| @AfterTest | |
| public void closeDriver() { | |
| driver.quit(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment