java - Getting error when selenium script run in background and executing switching from one tab to another -


exact error message : exception in thread "main" java.lang.indexoutofboundsexception: index: 1, size: 1 @ java.util.arraylist.rangecheck(arraylist.java:653)

code snippet:

arraylist<string> tabs = new arraylist<string>(driver.getwindowhandles()); driver.findelement(by.cssselector("body")).sendkeys(keys.control + "t"); driver.switchto().window(tabs.get(1)); driver.get(url2); 

you getting exception because populating tabs arraylist 1 tab.

if want browse url2 in new tab use below code snippet:

driver.findelement(by.cssselector("body")).sendkeys(keys.control + "t"); arraylist tabs = new arraylist(driver.getwindowhandles());  driver.switchto().window(tabs.get(0)); driver.get(url2); 

Comments

Popular posts from this blog

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -