0
// opening the base URL

driver1.get(baseUrl+"/");

// opening a new tab

driver1.findElement(By.cssSelector("Body")).sendKeys(Keys.COMMAND + "t");

driver1.get("my URL"); 

// getting back to the first tab             

driver1.findElement(By.cssSelector("body")).sendKeys(Keys.COMMAND, Keys.SHIFT, "{");

// I want to signup by clicking the sign up button

driver1.findElement(By.xpath("/html/body/div[1]/header/div[2]/button")).click();

The error that I get after running is : "Error communicating with the remote browser. It may have died."

But when I run the same code without the navigation, the button click works fine, then it means there is no problem with the xpath.

ramy
  • 11
  • 3
  • Why are you opening multiple tabs?? and where is problematic HTML?? – Saurabh Gaur Sep 12 '16 at 06:15
  • Which browser you are using ? In case of chrome and firefox, key for getting back to the first tab is cntrl+NumPad 1. I think because of wrong key, it is not able to navigate to first tab. Make sure control is on the first tab. – Rohhit Sep 12 '16 at 06:38
  • I am using Firefox, there is no problem with the navigation from tab to tab, but the button is not working. – ramy Sep 12 '16 at 11:38

2 Answers2

2

The information which browser you are using would be very interesting. And the webdriver doesn't need to control the visbile Tab. So i wouldn't let the Browser change the Tab and I would use the "switchTo" Method of the webdriver.
More information to this topic is here.

Community
  • 1
  • 1
Kikkirej
  • 611
  • 6
  • 8
  • 1
    Hi, I am using Firefox. – ramy Sep 12 '16 at 10:29
  • @ramy Firefox is definetly the easiest way to use Selenium. But watch out your Firefox isn't updating automatically. The required versions of the Third-Party-Software is [on the Selenium-Site](http://www.seleniumhq.org/about/platforms.jsp) – Kikkirej Sep 12 '16 at 10:38
1

As @Kikkirej mentuined, i see no reason to use sendKeys to switch between opened tabs. Use Selenium instead, it is a much better approach.

Edit: in addition, try to provide more information, especially the most basic part - the browser you are automating.

Nisim Naim
  • 151
  • 1
  • 15