Thanks for the wonderful explaination.Cleared all the basic concepts of Sets,Lists and their application in handling multiple tabs in Selenium Webdriver.
How to switch to incognito window form normal window, because while getting getWindowHandles() method getting only the normal windows ID'S not the incognito window ID's..please suggest us how to shift in between the two windows if one of the window is in incognito mode
@@Mukeshotwani in my requirement: checking the restriction of user login a application.so i opened the another window in incognito and checking it..so please suggest us to shift to incognito from normal window.
Hi Mukesh while switching to next window in IE browser, am getting "NoSuchWindowException : unable to get browser " could you please help me out in this
@@Mukeshotwani hi sir how to handle if you click to 1 link then open 2nd tab then go to 2nd tab and in 2nd tab available one link then click that link then open 3rd tab then how to perform in 3rd tab any thing. plzzz sir reply me
@Mukesh, I have one more doubt related to using single driver instance across multiple test case execution. Every time new driver instance is opened for test case execution, which I don't want to do it and also am not calling any driver. Close() method in @afterClass() annotation.
Hi small doubt sir..actually after login to one website,it's going to new window, I need to handle it..if I give xpath of one element in next window..it is not calculating.please help me
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"*[name='q']"} Getting above error during run time .. How to handle this error? Can you please help me out?
The set which is holding all the Windows will be unordered. Then how can we switch to a particular window (correct index is still unknown)using get index method of arraylist.
Hi Mukesh, when i run above code, i got error i.e Child window title is Jobs - Recruitment - Job Search - Employment -Job Vacancies - Naukri.com and also exception got NoSuchSessionException. please help
Sir totally one parent window has 3childs windows so I want to open each window individually then I have to perform some operation on each and every window and switch between each window randomly so I tried like this but I couldn't do so please say how to do?
Hi Mukesh, I have one scenario. Lets say i click on some link and as a result 2 popup window opened up. Now the requirement is that i need to navigate to second and perform some action and i need to switch to the first popup(not to the parent). So how to handle this case.
If insertion order is not preserved in Set then how can we get sequential order in getWindowHandles? Shouldn't pop up/new tab id be assigned in random order and come out in random order in Set??
Thank you very much mukesh garu..my all doubts clear about windowhandles with your video ...i have one small doubt with set interface we can handle tabs or not means tab by tab you used array list na thats y iam asking......
We converted set into array list as, in set we cannot use indexing option. And we directly can't store window handle elements in array list as selenium internally gives result in the form of set. So we need to store in set and then can convert to list if we need to use indexing option.
Hi Mukesh thank you for this video. I followed each and every for first example where I have 2 windows and count gives 2 as well but control does not switch to new window. Please help me to solve this problem. What do you think reasons behind not focussing on new window
Hi Mukesh, i like your all shared videos, i am Automation Tester(Selenium) , i have a request that can you please upload video for "How to read and verify pdf content in Selenium Webdriver" ??
Mukesh, how to ensure we are going to window in the order they opened?Because Set has random contents each time.This is the interview question.Plz clarify asap.
Hi Mukesh, set doesn't preserve the order, so in handling multiple windows also this will not be preserved and hence on converting the set to list we may get the order of windowids in different order in every run, which might cause problem, so do you suggest to switch to each window and verify the title first and then proceed with respective window testcases? Or there is some other easy approach?
Hi Rupjit, getWindowHandles follow LinkedHashSet so it will have value based on order. For example if you open tab 1, tab2, tab3 then it preserve the order.
Hi Mukesh, Set will not maintain any insertion order,If we are passing set (All saved window is )in List which maintains insertion order,In which order it will be stored. If we are accesing list.get(3) How can we ensure it is in the third window. It is the interview question where I am unable to explain properly.Could you help here
Hi Mukesh, Very nice video. I have one question. I am trying to navigate a url in a new opened tab in IE .As explained I followed everything. I am able to open tab but unable to open url . Even I tried by switching with child window I'd.. Kindly suggest
@@Mukeshotwani Thanks Mukesh ..i have one doubt here .if that is the case then why we need to store the tabs again in the List .we can proceed (or iterate through) set only right
I launched two browsers and tried to switch between these two using getwindowhandle. But in set it is only returning the current window. Used Code: String currentWindow = driver.getWindowHandle(); Set availableWindows = driver.getWindowHandles(); Why is it?
+parul khullar when you launch two browser then you will have two different instance so you can use both the instance separately. Switch window works when you have launched one window and then from that window if you open another tab or window then you will get count
Mukesh otwani thanks for your quick response. How can that be acheived. Even if I store windowhandles for both the browsers how will the switching be done.its like I have opened first and second browser, and currently I am on second one, and I need to switch. Can you guide
Hi Mukesh, This video is comparatively good. You explained very well.. Thanks for posting this Video.. I 'm actually facing an issue with switching between the tabs in headless mode for the same scenario u mentioned.. I get timeout error received message renderer exception and test fails.. Have you ever come across this issue? And do you have any possible solution for my case? Any suggestions and workaround is highly appreciated.. Thanks in advance. Good Luck.!
Hi Mukesh, Thanks for the great session, like all other videos. Just want to know how can we handle the notification window that u can see in Naukri page (GeoLocation with 'Sure' and 'Later' Options) I tried with all possibilities, chrome options. But no luck. would you please help me with that. Thanks in advance.
Hi Mukesh. I have a question. Like you have mentioned we can convert set to ArrayList and then we can use indexes to switch to windows. Can we do sth like this: LinkedHashSet windows=driver.getWindowHandles(); and then use the indexes as LInkedHashSet maintains the insertion order?
Hi Deekshith, not required but using this you can iterate via index as well. Set does not allow index so when we convert Set into List traversing can be easier. List in Java - th-cam.com/video/OFjYA0apYGY/w-d-xo.html Set in Java- th-cam.com/video/cKD5dtZ9m9U/w-d-xo.html
Hello Mukesh, I really admire what you have been doing. I find it as the best source to learn selenium. I do have a question regarding the mac "/usr/local/bin" folder. I always use system.setProperty, as I cannot access the BIN folder on my MAC as it says no such folder found. After searching on google it says if my mac is upgraded to El Capitan, i can't access the bin folder. Is there any other way to access the bin folder, so that I don't have to type System.setProperty, in every program. Thanks in Advance.
Sir still facing audio disturbance though your explanation is awesome but bcz of bad audio quality you got 7 dislikes otherwise no one can xplain better then you...kudos to you...blessings
Hi Mukesh, Thank you for providing valuable content. I had executed this program in Chrome it worked fine. But when i ran the same in firefox driver (by providing required firefox drivers) it got error. Thanks for the help in advance! package MouseActions; import java.util.Set; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class WindowHandling3 {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "E:\\Software Setups\\Gecko\\Gecko Mozilla\\geckodriver.exe"); WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.get("seleniumpractise.blogspot.com/2017/"); String parent = driver.getWindowHandle(); System.out.println("Parent value "+parent);
driver.findElement(By.xpath("//a[contains(@href,'www.google.com')]")).click(); Set a = driver.getWindowHandles(); System.out.println("Window count size : "+a.size()); System.out.println("Set values data : "+a);
for(String child:a) { System.out.println("Value of child: "+child);
} } In firefox browser, it got executed till this line System.out.println("Before statements"); and generated this error Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: *[name='q'] For documentation on this error, please visit: seleniumhq.org/exceptions/no_such_element.html
Nice video. Thanks for sharing. I am facing some issue with the below code. With this code, it is actually closing the main window first and then closing the child windows and finally displaying "NoSuchSessionException". Please let me know what is the issue with the code. import java.util.Set; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class WindowsHandlingTest { public static WebDriver driver; public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver", chromeDriverPath); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get("naukri.com"); String parent = driver.getWindowHandle(); System.out.println("Parent window id is " + parent); Set allWindows = driver.getWindowHandles(); for (String child : allWindows) { if (!parent.equalsIgnoreCase(child)) driver.switchTo().window(child); Thread.sleep(3000); driver.close(); } driver.switchTo().window(parent); System.out.println("Parent window title is " + driver.getTitle()); } }
@@Mukeshotwani Thanks Mukesh , i was still following your video offline .I have saved all your videos . But some flavour of comments was missing , so started back with online videos only ...:) Anyway thanks for your warm welcome
Bhai collections aur isme bhi bahut kharkharahat hai video ke beech mein, kaan ke parde hil jaate hain aur words miss ho ja rahe hain .... Baaki automation tester toh aap hi bana ke chhodoge. ✌
Hi Amit, Follow video in below manner learn-automation.com/selenium-webdriver-tutorial-for-beginners/ learn-automation.com/advance-selenium-webdriver-tutorials/
Hi guys, if your page doesn't have clickable links then try this code to open a new tab, and then you could use the logic explained in the video to handle tabs/windows. String url="example.com"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.open(arguments[0])", url);
@@Mukeshotwani Hi Mukesh, In my use case, I need to open a new tab and access some email, and switch back to the parent window to continue the testing on the main page. So I thought people who are working on such use cases, this code might be useful.
best video on window handler!!
Thanks Alex 😊
Duuuuuude you are my savior, I had been trying to do this for over 5 hours and after 13 minutes of your video it worked! thanks!
Please do something for audio disturbance. Content is great.
Indeed, this is the best video on window handling. Keep up the good work.
Thank you so much
Great video bro, can’t believe so many dislikes because a bit of background noise. But the content is one of the best I’ve seen.
Thank you mate, this comment means alot to me.
Hello sir.your genuine effort to teach can be seen.channel would grow for sure.
Thanks for the wonderful explaination.Cleared all the basic concepts of Sets,Lists and their application in handling multiple tabs in Selenium Webdriver.
Hi Mukesh,
Superb explaination of handling popups with debugging..Thank you very much.
Thanks Praveen :)
Hi Mukesh. Your all Videos are very very useful. Thank You so much. Just one thing.. if it can be taken care.. sound is less for some of the videos.
Sorry for that sound issue. Now audio is better I will record video soon with good sound as well.
@@Mukeshotwani Thank You so much.
How to switch to incognito window form normal window, because while getting getWindowHandles() method getting only the normal windows ID'S not the incognito window ID's..please suggest us how to shift in between the two windows if one of the window is in incognito mode
Hi Venkat, by default Selenium starts fresh session so why you need to start incognito windows?
@@Mukeshotwani in my requirement: checking the restriction of user login a application.so i opened the another window in incognito and checking it..so please suggest us to shift to incognito from normal window.
Thanks for this wonderful explanation.
Glad it was helpful! Saurabh
Hi Mukesh while switching to next window in IE browser, am getting "NoSuchWindowException : unable to get browser " could you please help me out in this
Thanks...video helps me to solve my problem...good explanation..Thanks once again
Thanks Gopi I am glad it helped you.
Thanks for your detailed description and it was really useful!!!
Thanks Animol
@@Mukeshotwani hi sir how to handle if you click to 1 link then open 2nd tab then go to 2nd tab and in 2nd tab available one link then click that link then open 3rd tab then how to perform in 3rd tab any thing. plzzz sir reply me
Hi Mukesh, if I'm in second window and go to third window and then back to second window means , how to handle this
Mukesh, where are you setting the driver path in your code?
Hi Manjunatha, here is the video for same th-cam.com/video/sTdXettm1y8/w-d-xo.html
@@Mukeshotwani appreciate your reply. Got the answer. Even you talked about using DriverManager also. Helpful. 👍
@Mukesh, I have one more doubt related to using single driver instance across multiple test case execution. Every time new driver instance is opened for test case execution, which I don't want to do it and also am not calling any driver. Close() method in @afterClass() annotation.
please share your code
Hi small doubt sir..actually after login to one website,it's going to new window, I need to handle it..if I give xpath of one element in next window..it is not calculating.please help me
Hi Naveen, what is the issue here? After switching you can work with any webelement on new window.
Why do we need to convert set into arraylist? Please explain.
Feel like best of all explanations loved ot sir ty
So nice of you Krishna thank you.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"*[name='q']"}
Getting above error during run time .. How to handle this error? Can you please help me out?
Yes Sarmistha, please share complete program so that I can guide you. As per exception your script is not able to find element.
The set which is holding all the Windows will be unordered. Then how can we switch to a particular window (correct index is still unknown)using get index method of arraylist.
the logic which u have shown in above video 'll it work if we have more than 2 tabs or upto 100 or even more ?
Hi Parth, yes it is applicable.
Hi Mukesh, how we will be sure that when we convert from set to list it will be stored in the same order in which order we wanted it to be?
Hi Tapas, getWindowHandles use LinkedHashSet internally so in which order windows will open you will get same order in List too.
@@Mukeshotwani Thank You Mukesh for clearing my doubt.
I have tried to sign in bookmyshow site through continue with google but I couldnot navigate to the other window could you pls help me
Hi Mukesh,
when i run above code, i got error i.e Child window title is Jobs - Recruitment - Job Search - Employment -Job Vacancies - Naukri.com and also exception got NoSuchSessionException. please help
Hi Praveen, please share program.
Sir totally one parent window has 3childs windows so I want to open each window individually then I have to perform some operation on each and every window and switch between each window randomly so I tried like this but I couldn't do so please say how to do?
Thanks Mukesh ji, I feel automation using Selenium is easy now, lots of thanks to your valuable videos. Looking forward to more such videos in 2018.
Awesome explaination @Mukesh Otwani 👍👍
Thanks Sanjay.. I am glad you liked my videos.
@@Mukeshotwani please make a video on how to switch from parent to child then again a new
child window
Very Very Useful, thank you Mukesh.
Hi Mukesh,
I have one scenario.
Lets say i click on some link and as a result 2 popup window opened up. Now the requirement is that i need to navigate to second and perform some action and i need to switch to the first popup(not to the parent). So how to handle this case.
Hi Abhisek as I mentioned in the video that once you get all windows as List then you can traverse in any direction.
I tired this in ie browser...but the window handler Id's for all the opened tabs are same..please suggest how to handle tabs/windows in IE browser
Please change of IE browser settings
If insertion order is not preserved in Set then how can we get sequential order in getWindowHandles? Shouldn't pop up/new tab id be assigned in random order and come out in random order in Set??
Thank you very much mukesh garu..my all doubts clear about windowhandles with your video ...i have one small doubt with set interface we can handle tabs or not means tab by tab you used array list na thats y iam asking......
We converted set into array list as, in set we cannot use indexing option. And we directly can't store window handle elements in array list as selenium internally gives result in the form of set. So we need to store in set and then can convert to list if we need to use indexing option.
Hi Mukesh thank you for this video. I followed each and every for first example where I have 2 windows and count gives 2 as well but control does not switch to new window. Please help me to solve this problem. What do you think reasons behind not focussing on new window
Hi Raju which browser you are using for Switching?
i am using internet explorer
Hi Mukesh, i like your all shared videos, i am Automation Tester(Selenium) , i have a request that can you please upload video for "How to read and verify pdf content in Selenium Webdriver" ??
NIce work and explanation brother Keep up the good work and i am really looking forward to the upcoming new videos.
Hi Pathak ji, stay tunned I have planned multiple videos in 2018..
Very helpful for me, Thank you
Glad it was helpful! Tahnks Shanmuga
Mukesh, how to ensure we are going to window in the order they opened?Because Set has random contents each time.This is the interview question.Plz clarify asap.
Hi Mukesh, set doesn't preserve the order, so in handling multiple windows also this will not be preserved and hence on converting the set to list we may get the order of windowids in different order in every run, which might cause problem, so do you suggest to switch to each window and verify the title first and then proceed with respective window testcases? Or there is some other easy approach?
Hi Rupjit, getWindowHandles follow LinkedHashSet so it will have value based on order. For example if you open tab 1, tab2, tab3 then it preserve the order.
All your videos are excellent. Its my request please don't used enhanced for loop while explaining any topic ,it is difficult to understand flow :)
Sure Saakshi noted your points. I will cover for basic for loop and enhanced for loop as well.
@@Mukeshotwani Thank you sir :)
Hello Sir, do we use the same code for switching to new tab and new window after click of any link ?
how is the start session on same window ?
Hi Malikah, if link opens in same window then no need to handle.
Hi Mukesh,
why you have used set interface instead of list directly.
Hi Bharathi, getWindowHandles return Set so first we need to store in Set
Thanks. This is working for me now.
Great
Hi Mukesh,
Set will not maintain any insertion order,If we are passing set (All saved window is )in List which maintains insertion order,In which order it will be stored.
If we are accesing list.get(3) How can we ensure it is in the third window.
It is the interview question where I am unable to explain properly.Could you help here
Hi Mukesh, Very nice video. I have one question. I am trying to navigate a url in a new opened tab in IE .As explained I followed everything. I am able to open tab but unable to open url . Even I tried by switching with child window I'd.. Kindly suggest
Hi Sasmita, for IE you might have to change registry value.
awesome sir, really much helpful
Hi Mukesh,
Can you please explain what is the difference between switching to windows and switching to tab?
For selenium both are same. Same command and same approach will work
@@Mukeshotwani okay
thanks Mukesh
Cheers
@@Mukeshotwani Thanks Mukesh ..i have one doubt here .if that is the case then why we need to store the tabs again in the List .we can proceed (or iterate through) set only right
Thank you for wonderful video. This is very informative.
Hi Mukesh, that was so good and worth learning. However, I have a problem similar to this. Can we have a discussion please?
Thanks, really good explanation!
I launched two browsers and tried to switch between these two using getwindowhandle. But in set it is only returning the current window. Used Code:
String currentWindow = driver.getWindowHandle();
Set availableWindows = driver.getWindowHandles();
Why is it?
+parul khullar when you launch two browser then you will have two different instance so you can use both the instance separately.
Switch window works when you have launched one window and then from that window if you open another tab or window then you will get count
Mukesh otwani thanks for your quick response.
How can that be acheived. Even if I store windowhandles for both the browsers how will the switching be done.its like I have opened first and second browser, and currently I am on second one, and I need to switch. Can you guide
I will try to create video on this soon.
Driver1 handle first browser
Driver2 handle another browser
Use above instance to handle respective browsers
That will be great.
Would be helpful if you can share some part of code here thanks,!
Hi Mukesh, This video is comparatively good. You explained very well.. Thanks for posting this Video..
I 'm actually facing an issue with switching between the tabs in headless mode for the same scenario u mentioned.. I get timeout error received message renderer exception and test fails.. Have you ever come across this issue? And do you have any possible solution for my case? Any suggestions and workaround is highly appreciated.. Thanks in advance. Good Luck.!
Hey Mohammed, here is the link for solution th-cam.com/video/C8GuQViFD3Y/w-d-xo.html
If in the child window, we will get another window then how to handle this sub-child window?
i want to select 2nd value of index for multiple dropdown in one class
Hi Mukesh,
Thanks for the great session, like all other videos. Just want to know how can we handle the notification window that u can see in Naukri page (GeoLocation with 'Sure' and 'Later' Options) I tried with all possibilities, chrome options. But no luck. would you please help me with that.
Thanks in advance.
Hi Kapali, This always works for me learn-automation.com/disable-chrome-notifications-selenium-webdriver/
Thank you. I shall try that. :)
Hi your videos are very helpful thank you
Most welcome Mate :) Keep visiting.
Hi Mukesh. I have a question.
Like you have mentioned we can convert set to ArrayList and then we can use indexes to switch to windows.
Can we do sth like this:
LinkedHashSet windows=driver.getWindowHandles();
and then use the indexes as LInkedHashSet maintains the insertion order?
Thanku very much. Nice explanation.
Thanks Divya :)
Please make on the Selenium in JavaScript also.
Hi mukesh sir, I wanna know that how to pass data from one page to another
Hi Jatin, you can return the values from methods and you can accept in next page.
hi,
sendkeys keyword is not working in chrome. the same code i have tried running it on Firefox, its working fine. could you help out in this?
HI Shibi,
Ideally it should work.. Please use latest chrome driver 2.38 chromedriver.storage.googleapis.com/index.html?path=2.38/
Hi Mukesh,
Can you please explain how to switch b/w 4 tabs and perform actions on all 4 tabs..Please give suggestions
Hi Pujitha, you can store them as list as I explained in below and then you can use index for switching.
Sir how handle multi windows at a time b/w switch them with the single loop ?
Hello
Can you please tell how to open multiple tabs in the same window
how we can connect our idm with python to download
Hi Deepu, Sorry I did not understand your question. Can you please elaborate?
Sir i am trying to make a downloader which will extract the link and download it through idm(internet download manger)
master , i have a doubt here why ur converting SET into LIST what is the reason.........
Hi Deekshith, not required but using this you can iterate via index as well. Set does not allow index so when we convert Set into List traversing can be easier.
List in Java - th-cam.com/video/OFjYA0apYGY/w-d-xo.html
Set in Java- th-cam.com/video/cKD5dtZ9m9U/w-d-xo.html
Thank you very much Mukesh:-)
If possible plz post some videos on C# for Selenium.
I didn't get you Brian...
HI mukesh ! Do u have tutorials on javascript ?If no,can u pls suggest a good youtube link for the same?I wanna learn javascript! thanx in advance !
how to automate the existing window or tab ,without opening new browser or tab
Sir its not going under if condition. I am writing the correct code but its still not entering the if condition
package forms;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class EdufectFormFullTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
String baseUrl="localhost:8080/WebApplication6/BasicForm1.jsp";
String name = "Mohit Sachdeva";
String age = "22";
String gender = "Male";
String line1 = "House No 401, Pocket 3";
String line2 = "Janta Flats, Paschim Puri";
String city = "New Delhi";
String zipcode = "110063";
String email = "mohitsachdeva.ms@gmail.com";
String mobile = "9999360340";
String working = "Yes";
String experience = "1";
String workUrl="localhost:8080/WebApplication6/WorkingDetails.jsp";
String namecomp="Edufect";
String designation="Java Trainee";
String background="Netbeans";
String year = "2018";
String salary = "10000";
String relocate = "No";
String projectLocation = System.getProperty("user.dir");
System.setProperty("webdriver.chrome.driver", projectLocation+"\\lib\\chromedriver\\chromedriver.exe" );
WebDriver driver = new ChromeDriver();
driver.get(baseUrl);
driver.findElement(By.id("name")).sendKeys(name);
driver.findElement(By.id("age")).sendKeys(age);
WebElement radio1 = driver.findElement(By.id("male"));
WebElement radio2 = driver.findElement(By.id("female"));
if(gender.equals("Male"))
{
//Radio Button1 is selected
radio1.click();
System.out.println("Radio Button Option 1 Selected");
}
if(gender.equals("Female"))
{
//Radio Button2 is selected
radio2.click();
System.out.println("Radio Button Option 2 Selected");
}
driver.findElement(By.id("line1")).sendKeys(line1);
driver.findElement(By.id("line2")).sendKeys(line2);
driver.findElement(By.id("city")).sendKeys(city);
driver.findElement(By.id("zipcode")).sendKeys(zipcode);
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("mobile")).sendKeys(mobile);
// Selecting CheckBox
WebElement option1 = driver.findElement(By.id("working"));
// This will Toggle the Check box
if(working.equals("Yes"))
{
option1.click();
}
// Check whether the Check box is toggled on
if (option1.isSelected()) {
System.out.println("Checkbox is Toggled On");
} else {
System.out.println("Checkbox is Toggled Off");
}
Select drpCountry = new Select(driver.findElement(By.name("experience")));
drpCountry.selectByVisibleText(experience);
driver.findElement(By.id("Submit")).submit();
System.out.println("Login Done with Submit");
if(gender.equals("null"))
{
driver.findElement(By.id("BasicForm1")).click();
System.out.println("Back to Basic Form");
}
if(working.equals("null"))
{
}
else
{
String parent=driver.getWindowHandle();
driver.findElement(By.id("WorkingDetails")).click();
System.out.println("Now Fill Working Details");
// To handle all new opened window.
Set allWindows = driver.getWindowHandles();
for(String child:allWindows)
{
if(!parent.equalsIgnoreCase(child))
{
driver.switchTo().window(workUrl);
driver.findElement(By.id("namecomp")).sendKeys(namecomp);
driver.findElement(By.id("designation")).sendKeys(designation);
Select bground = new Select(driver.findElement(By.name("background")));
bground.selectByVisibleText(background);
Select y = new Select(driver.findElement(By.name("year")));
y.selectByVisibleText(year);
driver.findElement(By.id("salary")).sendKeys(salary);
WebElement r1 = driver.findElement(By.id("Yes"));
WebElement r2 = driver.findElement(By.id("No"));
if(relocate.equals("Yes"))
{
//Radio Button1 is selected
r1.click();
System.out.println("Radio Button Option 1 Selected");
}
if(relocate.equals("No"))
{
//Radio Button2 is selected
r2.click();
System.out.println("Radio Button Option 2 Selected");
}
driver.findElement(By.id("SubmitPassport")).submit();
System.out.println("Login Done for Submit Passport");
}
}
}
}
}
Hello Mukesh, I really admire what you have been doing. I find it as the best source to learn selenium. I do have a question regarding the mac "/usr/local/bin" folder. I always use system.setProperty, as I cannot access the BIN folder on my MAC as it says no such folder found. After searching on google it says if my mac is upgraded to El Capitan, i can't access the bin folder.
Is there any other way to access the bin folder, so that I don't have to type System.setProperty, in every program.
Thanks in Advance.
Keep Rocking !
+Seenu Kaniappan 😀
it a great video it's work good but can we handle windows through title names????
Sir still facing audio disturbance though your explanation is awesome but bcz of bad audio quality you got 7 dislikes otherwise no one can xplain better then you...kudos to you...blessings
Yes Yash I am trying my best for Audio but some how audio is not up to mark. I will still try..
Thanks for nice comment.
please make a video on how to switch from parent to child then again a new
child window
If I want to scroll child page instead of parents then how it will be possible?
Very Good explanation , but lot of audio disturbance
sir its not working its opening the tab and not navigate to that window
Hi Akash,
may be some code issue. Please send code to mukeshotwani@learn-automation.com
sir, audio disturbance is too high, ur volume is too low, pls do something, ur hardwork is going waste
Hi Amar,
I will try to fix soon
sir your volume is very low.. please do something for it
Hi Rohit in recent videos I have improved sound quality.
A lot of audio disturbance, but helpful session thank you.
Thanks Dipali I am working on the audio part... 🙏
Thank you
You're welcome Veera
Thank you Mukesh
please make an tutorial in findbys and findAll
best video
Thanks Sutapa
Hi Mukesh, Thank you for providing valuable content.
I had executed this program in Chrome it worked fine. But when i ran the same in firefox driver (by providing required firefox drivers) it got error. Thanks for the help in advance!
package MouseActions;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WindowHandling3 {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "E:\\Software Setups\\Gecko\\Gecko Mozilla\\geckodriver.exe");
WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.get("seleniumpractise.blogspot.com/2017/");
String parent = driver.getWindowHandle();
System.out.println("Parent value "+parent);
driver.findElement(By.xpath("//a[contains(@href,'www.google.com')]")).click();
Set a = driver.getWindowHandles();
System.out.println("Window count size : "+a.size());
System.out.println("Set values data : "+a);
for(String child:a)
{
System.out.println("Value of child: "+child);
if(!parent.equalsIgnoreCase(child))
{
System.out.println("Under If condition");
driver.switchTo().window(child);
System.out.println("Driver Title: "+driver.getTitle());
System.out.println("Before statements");
driver.findElement(By.name("q")).sendKeys("selenium");;
//driver.findElement(By.cssSelector("input.gLFyf.gsfi")).sendKeys("Selenium");;
Thread.sleep(3000);
driver.close();
//driver.quit();
}
System.out.println("Completed 1 iteration");
}
driver.switchTo().window(parent);
Thread.sleep(3000);
driver.close();
}
}
In firefox browser, it got executed till this line System.out.println("Before statements");
and generated this error
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: *[name='q']
For documentation on this error, please visit: seleniumhq.org/exceptions/no_such_element.html
Hi Vaseem, its strange behavior, can you debug your code th-cam.com/video/rXXeHfvbddo/w-d-xo.html
Nice video. Thanks for sharing.
I am facing some issue with the below code. With this code, it is actually closing the main window first and then closing the child windows and finally displaying "NoSuchSessionException".
Please let me know what is the issue with the code.
import java.util.Set;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class WindowsHandlingTest {
public static WebDriver driver;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("naukri.com");
String parent = driver.getWindowHandle();
System.out.println("Parent window id is " + parent);
Set allWindows = driver.getWindowHandles();
for (String child : allWindows) {
if (!parent.equalsIgnoreCase(child))
driver.switchTo().window(child);
Thread.sleep(3000);
driver.close();
}
driver.switchTo().window(parent);
System.out.println("Parent window title is " + driver.getTitle());
}
}
Everything is fine but Scenario: when the multiple windows are already open, then that "Set allwindows " can't count the windows numbers.
I am so happy supper annoying pop-up days are over. Yes, u see some here and there but not like before where every page u land has millions of pop-ups
Welcome mate
nice video
Thanks Neeti, welcome back to the channel
@@Mukeshotwani Thanks Mukesh , i was still following your video offline .I have saved all your videos . But some flavour of comments was missing , so started back with online videos only ...:) Anyway thanks for your warm welcome
Hey nice! Can you share your code, please?
Hi Alex I have code posted on my blog please have a look
learn-automation.com/handle-multiple-windows-in-selenium-webdriver/
Nice bro but still u better to explain clearly some words can't understand audio is not perfect somewhat better
HI Rajesh this video is old try new video th-cam.com/video/pZdMsLKAjs4/w-d-xo.html
Thanku mukesh
Video request: Please make a video on *how to read data from json in selenium and verify jason data with webpage?*
HI Bhavesh will upload soon. As of now this will help www.mkyong.com/java/json-simple-example-read-and-write-json/
Thank You.
video is really good bt there is so Audio disturbance
Bhai collections aur isme bhi bahut kharkharahat hai video ke beech mein, kaan ke parde hil jaate hain aur words miss ho ja rahe hain .... Baaki automation tester toh aap hi bana ke chhodoge. ✌
Thank you Manish bhai.. Collection ka alag Maza hai har jagah Selenium me b Rest Assured b.
videos seems not in sequencing manner
Hi Amit,
Follow video in below manner
learn-automation.com/selenium-webdriver-tutorial-for-beginners/
learn-automation.com/advance-selenium-webdriver-tutorials/
Hi Mukesh, I have sent you one email regarding my doubt. Hope you get time to check that.
Thanks
Kindly use a better mic, the content is really good but the audio disturbance is just horrible :(
Hi guys, if your page doesn't have clickable links then try this code to open a new tab, and then you could use the logic explained in the video to handle tabs/windows.
String url="example.com";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.open(arguments[0])", url);
Hey Pavan thank for the code and your input.
I am wondering if link is not clickable then as per user perspective he wont be access the link.
@@Mukeshotwani Hi Mukesh, In my use case, I need to open a new tab and access some email, and switch back to the parent window to continue the testing on the main page. So I thought people who are working on such use cases, this code might be useful.
@@theriderpanda Yes definitely it would help others and yes now I can understand your scenario too.
tq so much i searching everywhere but u only give me solution