Selenium click Event Sample Program in Java

(Last Updated On: August 11, 2016)

Selenium click Event:

In the post, we are going to load www.javadomain.in site using selenium in java and JSP and Servlet page will be clicked after the page load.

Selenium Java Program to Click:

import java.io.File;

import org.openqa.selenium.ie.InternetExplorerDriver;

public class SeleniumClickEvent {
	public static void main(String[] args) {
		File file = new File("D:/IEDriverServer.exe");
		System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
		InternetExplorerDriver driver = new InternetExplorerDriver();
		// The below line open the javadomain.in in IE browser
		driver.get("http://www.javadomain.in");
		// menu-item-1381 is the ID of the JSP and Servlet page of Javadomain.in
		// site, so it will be clicked
		driver.findElementById("menu-item-1381").click();
	}
}

Output:
1. Javadomain.in will be opened in the IE browser.
2. JSP and Servlet Page will be clicked after the page load.

Note:
Here we performed click with ID using findElementById(). But the same can be achieved using any of the below,

1. findElementByClassName()
2. findElementByCssSelector()
3. findElementByLinkText()
4. findElementByName()
5. findElementByPartialLinkText() etc…

199 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *