@shyann
To avoid selenium redirect using Java, you can try the following methods:
- Disable redirections: You can set ChromeOptions to disable all redirections in Chrome driver by adding the following code:
1
2
3
4
|
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-notifications");
|
- Set page load strategy: You can set the page load strategy to none to prevent automatic redirections in Selenium WebDriver:
1
|
driver.manage().timeouts().pageLoadStrategy(PageLoadStrategy.NONE);
|
- Handle redirection manually: You can handle redirection manually by getting the current URL and checking if it matches the expected URL. If not, you can navigate to the expected URL:
1
2
3
4
|
String currentURL = driver.getCurrentUrl();
if(!currentURL.equals(expectedURL)) {
driver.navigate().to(expectedURL);
}
|
- Use wait conditions: You can use WebDriverWait to wait for specific conditions before proceeding, such as waiting for a specific URL to load, before continuing with the test execution:
1
2
|
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.urlToBe(expectedURL));
|
By using these methods, you can avoid redirections in Selenium using Java.