Event handling for Selenium Webdriver

Source: Internet
Author: User

Package Www.zr.com;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webelement;import Org.openqa.selenium.support.events.abstractwebdrivereventlistener;public class Zr_eventlistener extends Abstractwebdrivereventlistener {//indicates an event that needs to be listened to when the browser browses to a page @overridepublic void Afternavigateto (String url,webdriver Driver) {System.out.printf ("after Navigate to" +url);} Represents an event that is required to listen for browser fallback after browsing a page @overridepublic void Afternavigateback (Webdriver driver) {System.out.printf ("after Navigate back to "+driver.getcurrenturl ());} Represents an event that is required to listen for a mouse click on an element on the page @overridepublic void Afterclickon (webelement webelement,webdriver driver) { System.out.printf ("After click on" +webelement.gettext ());}}

  

ImportOrg.openqa.selenium.support.events.EventFiringWebDriver;ImportWww.zr.com.zr_EventListener; Public classAutorunner_test { Public Static voidmain (String [] args) {//Test URLsString url = "Http://www.zr.com"; //Chromedriver.exe file AddressString chromedriver_fileaddress = "C:/Program Files (x86)/google/chrome/application/chromedriver.exe"; //Setting Environment VariablesSystem.setproperty ("Webdriver.chrome.driver", chromedriver_fileaddress); /****** Open the application with a fixed port ************/chromedriverservice.builder Builder=NewChromedriverservice.builder (); Chromedriverservice Chromeservice= Builder.usingdriverexecutable (NewFile (chromedriver_fileaddress)). Usingport (3333). build (); Try{Chromeservice.start (); }Catch(IOException e) {e.printstacktrace (); } webdriver Xuyun_driver=NewChromedriver (chromeservice);
        /****** Open the application with a fixed port ************/
// Listening for events
New Eventfiringwebdriver (Xuyun_driver);
New

Eventfiringdriver.findelement (By.id ("PERSONBTN"

}

Operation Result:

After Navigate to http://www.zr.com

After click on Please login

Event handling for Selenium Webdriver

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.