The xpaths will be the same regardless of which browser you use. to make a script work in multiple browsers, you can create multiple TestNg suites for different browsers, and have the same script for all the suites. All you need to change in the suites are the Browser classes. Consider the following script
You can run this entire code in one go. All the test suites will be executed one after the other
class MultipleBrowser{ //for Firefox @Test public void FirefoxBrowser() { WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); driver.findElement(By.id("lst-ib")).sendKeys("Automating in firefox Browser"); } //for ChromeBrowser @Test public void ChromeBrowser() { WebDriver driver = new ChromeDriver(); //only the class is changed from firefoxDriver to ChromeDriver driver.get("http://www.google.com"); driver.findElement(By.id("lst-ib")).sendKeys("Automating in Chrome Browser"); } //for InternetExplorer @Test public void IEBrowser() { WebDriver driver = new InternetExplorerDriver(); //only the class is changed from ChromeDriver to IEDriver driver.get("http://www.google.com"); driver.findElement(By.id("lst-ib")).sendKeys("Automating in IE Browser"); } }