Webdriver Driver = new Chromedriver ();
- XPath positioning: driver.findelement (By.xpath ("//div[@id = ' register518 ']/span[2]");
- ID Locator: Driver.findelement (by.id ("Model_phone"));
- LinkText positioning: Driver.findelement (By.linktext ("Baidu"));
- CSS positioning: driver.findelement (By.cssselector ("Span.bankLogo.bank_ICBC"));
- Empty the input box: driver.findelement (By.id ("Model_phone")). Clear ();
- Browser maximization: Driver.manage (). window (). Maximize ();
- Refresh page: Driver.navigate (). Refresh ();
- Page fallback: Driver.navigate (). back ();
- Page forward: Driver.navigate (). Forward ();
- Open page: Driver.navigate (). to ("http://www.baidu.com");
- Open page: Driver.get ("http://www.baidu.com");
- Close page: Driver.close ();
- Current address: Driver.getcurrenturl ();
- Explicit wait: explicitly tells Webdriver to wait on a specific condition.
- Webdriverwait wait= New Webdriverwait (driver,30);
- Wait.until (expectedconditions.invisibilityofelementlocated (By.id ("Model_phone"));
- Implicit wait: Tells Webdriver a maximum timeout period, and if the waiting condition is satisfied before the timeout expires, you do not need to wait for the next step to proceed immediately.
- Driver.manage (). Timeouts (). implicitlywait (Timeunit.seconds);
- Pause Operation: tread.sleep (1000);
- Intercepting screens: Using the Getscreenshotas () method
- File srcfile = ((takesscreenshot) driver). Getscreenshotas (Outputtype.file);
- Fileutils.copyfile (srcfile,new file ("directory filename. png"));
- Copy file: Use the Filehandler.copy () method to copy the file.
- Filehandler.createdir ("c:\\ source directory"), new File ("c:\\ new Directory"), all files from the source directory to the new directory.
- Filehandler.createdir ("File specified by c:\\ source directory"), new File ("c:\\ new Directory"), and the specified file to the new directory.
- Filehandler.createdir ("c:\\ source directory"), new File ("c:\\ new Directory"), ". Suffix name"); The file that specifies the suffix is copied to the new directory.
- Create directory: Use the Filehandler.createdir () method to create a directory.
- Import Org.openqa.selenium.io.FileHandler;
- public static void Main (string[] args) throws Exception {try{Filehandler.createdir (new File ("C:\\newdi Rectory ")); }catch (IOException e) {e.printstacktrace (); }
- }
- Delete directory: Use the Filehandler.delete () method to delete the directory.
- Filehandler.delete (New File ("C:\\directory"));
- Read file: Use the Ilehandler.readasstring () method to read the file.
- String file=filehandler.readasstring (new file directory filename));
- System.out.println (file);
- Compressed directory:
- Zip.zip (New file ("c:\\ source directory"), new file ("C:\\ compressed file)";
- filehandler.iszipped ("file"); Determine if the file is compressed;
- Zip.unzip ("c:\\ compressed File"), New file ("c:\\ extract file)"; unzip the file;
Selenium2-java syntax