Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98814

I am opening a browser and logging in into a webpage. Now i want to open a new tab and work with another link in the newly opened tab

$
0
0
public static void main(String[] args) {

System.setProperty("webdriver.gecko.driver", "geckodriver");
WebDriver driver = new FirefoxDriver();

String baseUrl = "https://accounts.zoho.in/signin?servicename=google";

driver.get(baseUrl);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement email = driver.findElement(By.xpath("//*[@id=\"login_id\"]"));
email.sendKeys("xxxxxxxx.xmail.com");
WebElement nextbutton = driver.findElement(By.xpath("//*[@id=\"nextbtn\"]"));
nextbutton.click();
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
WebElement password = driver.findElement(By.xpath("//*[@id=\"password\"]"));
password.sendKeys("123456789");
WebElement submit = driver.findElement(By.xpath("//*[@id=\"nextbtn\"]"));
submit.click();

driver.manage().timeouts().implicitlyWait(20000, TimeUnit.MICROSECONDS);

String oldTab = driver.getWindowHandle();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
ArrayList<String> newTab = new ArrayList<String>(driver.getWindowHandles());
newTab.remove(oldTab);
driver.switchTo().window(newTab.get(0));
}

Can someone help me with this code please? My code is not working (I am a total beginner). I am able to login as per my requirement, But i am not able to open a new tab and also need help in going to another link in the newly opened tab.

org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at newProject.MyFirstClass.main(MyFirstClass.java:80)

Viewing all articles
Browse latest Browse all 98814

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>