SELENIUM2 Learning -019-webui Automation Real instance -017-get browser type

Source: Internet
Author: User

Web UI Automation Script distribution sometimes need to get information about the browser, this article gives a brief way to get the browser type, please refer to the small owners. If there is any deficiency, please ask the great God to correct me, I appreciate it!

Gossip less, on yards.

1     /**2 * Get Browser type, for execute JavaScript by Selenium3      * 4      * @authorAARON.FFP5      * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java getbrowertype, 2015-7-26 12:17:12 Exp $6      * 7      * @returnBrowser Type {chrome| Firefox| internetexplorer| Safari}8      */9      PublicString Getbrowsertype () {TenString browser = ""; One          A         Switch( This. webdriver.tostring (). Split (":") [0]) { -              Case"Chromedriver": -Browser = "Chrome"; the                  Break; -              Case"Firefoxdriver": -Browser = "Firefox"; -                  Break; +              Case"Internetexplorerdriver": -Browser = "InternetExplorer"; +                  Break; A              Case"Safaridriver": atBrowser = "Safari"; -                  Break; -             default: -Browser = "Chrome"; -                  Break; -         } in          -         returnBrowser; to}

This method is relatively simple and easy to understand. At the same time, I found that in the course of the script, if the UI Automation test pin This error message, in addition to the corresponding errors in the information, but also contains the driver version, selenium version, work machine, browser and other details, if you want to get more detailed information, To record the response information in subsequent log generation, it is possible to obtain the appropriate information from the exception by artificially making the exception. (This method of access is updated later, please expect)

Interested in the small owners, you can try the above exception to capture the information method. If the great God has a better way, please inform, thank you very much!

At this point, theWebUI automation function test Script No. 017-Get the browser type successfully completed, I hope this article can give beginners Selenium you a reference.

Finally, very grateful to the pro-stop, I hope this article can be pro helpful. Warmly welcome the kiss to discuss together and progress together. Thank you so much! ^_^

SELENIUM2 Learning -019-webui Automation Real instance -017-get browser type

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.