Finally, start writing for the first time ~
Let's have a simple one ~
PackageSelenium;Importorg.openqa.selenium.Dimension;ImportOrg.openqa.selenium.WebDriver;ImportOrg.openqa.selenium.firefox.FirefoxDriver; Public classSeleniumjava { Public Static voidMain (string[] args) {Dimension Dimension; //declare variables for use belowDimension drsize =NewDimension (850,1280);//Create an instance and assign a value (350,600)//system.setproperty ("Webdriver. Firefox.driver "," C://Firefox//Firefox.exe ");
//if the browser is not the default path installation, you need to specify a pathWebdriver Dr =NewFirefoxdriver ();//Open Firefox BrowserDr.manage (). window (). setSize (Drsize);//set the form size to DrsizeDr.manage (). window (). Maximize ();//Maximize Your browserDr.get ("http://www.baidu.com");//Open Web pageDimension = Dr.manage (). window (). GetSize ();//Get Browser sizeSystem.out.print ("Browser current height is" +dimension.getheight () + "; Browser current width is" +dimension.getwidth ());
//output Browser height and widthDr.close (); }}
The Dimension class, which encapsulates the height and width of a component.
Dr.manage (). window (). setSize (Drsize); Set the form size.
Dr.manage (). window (). Maximize (); Set the form to maximized.
Dr.manage (). window (). GetSize (); Gets the form size, has a return value, and needs to be copied to the variable.
Selenium+java First Demo