Let’s consider the following sample HTML code snippet as a reference point.
You can use same fashion for any of the selenium command like i am using for click.
The click command emulates a click operation for a link, button, checkbox or radio button. It takes a locator (an identifier for which HTML element the command refers to) as an argument.
Using Selectors with Click Command:
xpath
This allows clicking on an element using an XPath expression. Example
selenium.click("xpath=//input[@name=webButton' and @type='submit']");
css
CSS locator is used with Selenium commands to uniquely identify an object or element on a web page. Example,
selenium.click("css=input[name=webButton]”);
name
The name selector is used to click the first element with the specified @name attribute. Example,
selenium.click("name=webButton”);
or
selenium.click("webButton");
id
This allows click on an element with the specified @id attribute. Example,
selenium.click("id=webButton”);
link
This allows clicking on a link element which contains text matching the specified pattern. Example,
selenium.click("link=Go Home”);
- <!DOCTYPE HTML>
- <html>
- <head>
- <script type="text/javascript">
- function jsFunction(){
- alert("Welcome to Selenium UI Automation Testing !");
- }
- </script>
- </head>
- <body>
- <input type="submit" id="webButton" onclick="jsFunction()" value="Click It" />
- </body>
- </html>
You can use same fashion for any of the selenium command like i am using for click.
The click command emulates a click operation for a link, button, checkbox or radio button. It takes a locator (an identifier for which HTML element the command refers to) as an argument.
Using Selectors with Click Command:
xpath
This allows clicking on an element using an XPath expression. Example
selenium.click("xpath=//input[@name=webButton' and @type='submit']");
css
CSS locator is used with Selenium commands to uniquely identify an object or element on a web page. Example,
selenium.click("css=input[name=webButton]”);
name
The name selector is used to click the first element with the specified @name attribute. Example,
selenium.click("name=webButton”);
or
selenium.click("webButton");
id
This allows click on an element with the specified @id attribute. Example,
selenium.click("id=webButton”);
link
This allows clicking on a link element which contains text matching the specified pattern. Example,
selenium.click("link=Go Home”);