Problem point: Too long did not write selenium code, incredibly put driver common problem forget, namely: Each write a test class, the execution process will create a new window, this should say is very unprofessional.
Probably think of a method, although it does not seem professional, but feel able to use it is very happy.
Steps to resolve:
1 Create a method to get driver Getdriver ()
2 Create a member variable and assign Getdriver () to a member variable
3 Other business classes when using driver, you can get the same driver through the parent class. Driver Way
public class login{private static final String username= "[email protected]"; private static final String password= "123456"; public static final Webdriver driver=getdriver (); Public Login () {}//Get driver public static Webdriver Getdriver () {System.setproperty ("Webdriver.chrome.driver", "othe r/. /.. /.. /chromedriver.exe "); Webdriver drivers=new chromedriver (); return drivers; } public static void Loginuser () {Webdriver driver=login.driver; Driver.get ("Http://testAdress.com/#/login"); Driver.navigate (). Refresh (); Sleep (1); Driver.findelement (By.xpath ("/html/body/div[1]/div[1]/div/div[2]/div[2]/div/div[1]/form/div[1]/div/div/input") ). SendKeys (UserName); Driver.findelement (By.xpath ("/html/body/div[1]/div[1]/div/div[2]/div[2]/div/div[1]/form/div[2]/div/div[1]/ Input ")). SendKeys (password); Driver.findelement (By.xpath ("/html/body/div[1]/div[1]/div/div[2]/div[2]/div/div[1]/form/div[4]/button")). Click (); }}
Hint: If it is useful, please do not copy, because only a part of the code, not the complete class paste out!
Selenium +java multiple Common driver issues