以微信公众号登陆界面为例,
找到相对应的Xpath的方法,
核心代码:
System.setProperty(“webdriver.chrome.driver”,“ C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe”); WebDriver driver = new ChromeDriver(); driver.get(“https://mp.weixin.qq.com”); //插入用户名以及密码 ((ChromeDriver) driver).findElementByXPath("//*[@id="header"]/div[2]/div/div/form/div[1]/div[1]/div/span/input").clear(); ((ChromeDriver) driver).findElementByXPath("//*[@id="header"]/div[2]/div/div/form/div[1]/div[1]/div/span/input").sendKeys(“***”); ((ChromeDriver) driver).findElementByXPath("//*[@id="header"]/div[2]/div/div/form/div[1]/div[2]/div/span/input").clear(); ((ChromeDriver) driver).findElementByXPath("//*[@id="header"]/div[2]/div/div/form/div[1]/div[2]/div/span/input").sendKeys(“***”); //模拟登陆 ((ChromeDriver) driver).findElementByXPath("//*[@id="header"]/div[2]/div/div/form/div[4]/a").click();