Selenium click Event Sample Program in Java
Selenium click Event:
In the post, we are going to load www.ngdeveloper.com site using selenium in java and JSP and Servlet page will be clicked after the page load.
Selenium Java Program to Click:
[java]
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 ngdeveloper.com in IE browser
driver.get("http://www.ngdeveloper.com");
// 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();
}
}
[/java]
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…