Although Webdriver has the best support for Firefox, previously written scripts are also running in the Firefox browser, but recently the project has been integrated to find that the newly integrated features are not very supportive of Firefox, and there are no plans to make browser compatibility improvements in the near future. So my automation scripts are going to be re-edited and run on a well-supported Chrome browser. Having said so many backgrounds, let's get down to the chase.
1. You need to download CHROMEDRIVER.HTTP://CHROMEDRIVER.STORAGE.GOOGLEAPIS.COM/INDEX.HTML2 first. Unzip the downloaded file, Copy the Chromedriver.exe to the Chrome root directory, typically in the Appication directory 3. You can use Chromedriver, if you copy Chromedriver to the project root, you don't need setproperty, but I put it in the chrome root. directory, so you set the drive path. System.setproperty ("Webdriver.chrome.driver", "C:\\Program Files" (x86) \\Google\\Chrome\\Application\\ Chromedriver.exe "); Webdriver driver=new chromedriver (); //Initialize browser 4. After three steps, you can actually go directly to the script. However, sometimes it is possible to set the agent and port as needed. Although my own script does not need to be set, it uses the default proxy and port. But before the script made a mistake, I mistakenly think it is a proxy setup has a problem, so also write script to proxy reset the next, later still did not pass, colleagues help me after analysis said no, Magic commented out code incredibly passed, really do not know where the error before, OK, it is learning. You can set the runtime proxy by the following code:/* String proxyipandport= "localhost:8080"; desiredcapabilities cap = new Desiredcapabilities (); proxy proxy=new proxy (); proxy.sethttpproxy (proxyipandport). Setftpproxy ( Proxyipandport). Setsslproxy (Proxyipandport); cap.setcapability (CapabilityType.ForSeleniumServer.AVOIDING_ PROXY, True); cap.setcapability (CapabilityType.ForSeleniumServer.ONLY_PROXYING_SELENIUM_TRAFFIC, True); system.setproperty ("http.nonproxyhosts", "localhost"); cap.setcapability (Capabilitytype.proxy, proxy); * * As for Firefox, it also automatically generates a profile every time Firefox is started, instead of using the current Firefox profile, which can be set by Firefoxprofile. Temporarily do not write first, if any need, can leave a message.
Selenium Chrome Browser startup and proxy settings