Earlier nosotros get got learnt nearly how to switching betwixt windows In selenium webdriver software testing tool equally described on THIS PAGE. together with live on amongst multiple IFrames In THIS POST. As all of us are used to live on amongst multuple tabs, to a greater extent than or less peoples don't similar to live on amongst multiple windows. So principal enquiry Is -> How to open novel tab In selenium webdriver software exam together with thence how to switch betwixt 2 tabs together with accept required actions. Also yous tin john unopen all tabs using Robot shape equally described In THIS POST.
How to opened upward novel tab
WebDriver software automation testing tool produce non get got whatsoever built In method using which nosotros tin john opened upward novel tab. Normally nosotros are using CTRL + t Keys to opened upward novel tab In Browser. We tin john produce same affair In webdriver software exam for opening novel tab In selenium webdriver, Bellow given syntax volition opened upward novel tab In your driver browser Instance.
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
How to switch betwixt 2 tabs
For switching betwixt tabs of browser, We are using CTRL + Tab keys. Same way, bellow given syntax volition switch betwixt tabs together with pick out the content of selected tab.
//Switching betwixt tabs using CTRL + tab keys. driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"\t"); //Switch to electrical flow selected tab's content. driver.switchTo().defaultContent();
I get got created uncomplicated example on tab switching for your ameliorate understanding. It volition Open novel tab together with thence switch betwixt them to perform dissimilar actions on both tab's pages.
package Testing_Pack; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; world shape Tabs { WebDriver driver; @BeforeTest world void setup() throws Exception { driver = novel FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get(" "); } @Test world void openTab() { //Open tab 2 using CTRL + t keys. driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t"); //Open URL In s tab. driver.get(" "); //Call switchToTab() business office to switch to 1st tab switchToTab(); //perform required actions on tab 1. driver.findElement(By.xpath("//input[@id='6']")).click(); driver.findElement(By.xpath("//input[@id='plus']")); driver.findElement(By.xpath("//input[@id='3']")); driver.findElement(By.xpath("//input[@id='equals']")); //Call switchToTab() business office to switch to s tab. switchToTab(); //perform required actions on tab 2. driver.findElement(By.xpath("//input[@name='FirstName']")).sendKeys("hi"); driver.findElement(By.xpath("//input[@name='LastName']")).sendKeys("test"); //Call switchToTab() business office to switch to 1st tab switchToTab(); //perform required actions on tab 1. String str = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value"); System.out.println("Sum trial Is -> "+str); } world void switchToTab() { //Switching betwixt tabs using CTRL + tab keys. driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"\t"); //Switch to electrical flow selected tab's content. driver.switchTo().defaultContent(); } }
This way, We tin john purpose keyboard actions to switch betwixt tabs In selenium webdriver software automation testing tool.
http://www.software-testing-tutorials-automation.com/