Reputation: 11
I am working on Salesforce automation. There is a scenario which uses the one time sign on:
I am able to login in Salesforce application but unable to open a new tab I have already tried below solution:
Solution 1:
Actions act = new Actions(driver);
act.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform();
Solution 2:
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_T);
Solution 3:
String KeyString = Keys.CONTROL+"t";
driver.findElement(By.tagName("body")).sendKeys(KeyString);
Solution 4:
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL+"t");
Has anyone faced issue? What could be the possible solution for this?
Upvotes: 0
Views: 186
Reputation: 573
You can use JavascriptExecutor to switch to the new tab. Switching doesn't work automatically. So it's a two phase solution.
((JavascriptExecutor) driver).executeScript("window.open('http://example.com/','_blank');");
Above code will open example.com in a new tab.
Now you can switch using something like below:
Set<String> tab_handles = driver.getWindowHandles();
int number_of_tabs = tab_handles.size();
int new_tab_index = number_of_tabs-1;
driver.switchTo().window(tab_handles.toArray()[new_tab_index].toString());
Upvotes: 1