Click on any html element using different locators

 * Click on any html element in the webpage as long as you can use the locators to identify them.
 * Assume that you have Internet Explorer and Selenium Server is running on your
 *  computer on default port 4444. Otherwise, change accordingly in the constructor.
 * @Author: Xuan Ngo
import com.thoughtworks.selenium.DefaultSelenium;
public class ClickAny
  private DefaultSelenium m_oBrowser = null;
  public static void main(String[] args)
    ClickAny oClickAny = new ClickAny();
    // Click on any html element in the webpage.
  // Constructor
  public ClickAny()
    this.m_oBrowser = new DefaultSelenium("localhost", 4444, "*iexplore", "");
    this.m_oBrowser.start(); // Start Selenium.""); // Open the webpage.
  // Click on any html element in the webpage.
  public void runExamples()
    // Click on Submit button using NAME locator."name=submit_button"); 
    // Click on <li> using ID locator."id=unique-link-id");
    // Click on <li> using XPATH locator."xpath=//li[contains(text(), 'using the xpath')]"); 
    //this.m_oBrowser.stop(); // Close Selenium.
HTML icon ClickAnyElementExample.html1.24 KB