Selenium2-java syntax

Source: Internet
Author: User
Tags close page create directory xpath

Webdriver Driver = new Chromedriver ();
  1. XPath positioning: driver.findelement (By.xpath ("//div[@id = ' register518 ']/span[2]");
  2. ID Locator: Driver.findelement (by.id ("Model_phone"));
  3. LinkText positioning: Driver.findelement (By.linktext ("Baidu"));
  4. CSS positioning: driver.findelement (By.cssselector ("Span.bankLogo.bank_ICBC"));
  5. Empty the input box: driver.findelement (By.id ("Model_phone")). Clear ();
  6. Browser maximization: Driver.manage (). window (). Maximize ();
  7. Refresh page: Driver.navigate (). Refresh ();
  8. Page fallback: Driver.navigate (). back ();
  9. Page forward: Driver.navigate (). Forward ();
  10. Open page: Driver.navigate (). to ("http://www.baidu.com");
  11. Open page: Driver.get ("http://www.baidu.com");
  12. Close page: Driver.close ();
  13. Current address: Driver.getcurrenturl ();
  14. 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"));
  15. 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);
  16. Pause Operation: tread.sleep (1000);
  17. Intercepting screens: Using the Getscreenshotas () method
      • File srcfile = ((takesscreenshot) driver). Getscreenshotas (Outputtype.file);
      • Fileutils.copyfile (srcfile,new file ("directory filename. png"));
  18. 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.
  19. 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 (); }
      • }
  20. Delete directory: Use the Filehandler.delete () method to delete the directory.
      • Filehandler.delete (New File ("C:\\directory"));
  21. Read file: Use the Ilehandler.readasstring () method to read the file.
      • String file=filehandler.readasstring (new file directory filename));
      • System.out.println (file);
  22. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.