What is Selenium?
Selenium is a browser automation tool which lets you automated operations like – type, click, and selection from a drop-down of a web page.
How is Selenium different from commercial browser automation tools?
Selenium is a library which is available in a many of languages i.e. Java, C#, python, ruby, PHP etc while most commercial tools are limited in their capabilities of being able to use just one language. Moreover, many of those tools have their own proprietary language which is of little use outside the domain of those tools. Most commercial tools focus on record and replay while Selenium emphasis on using Selenium IDE (Selenium record and replay) tool ONLY to get acquainted with Selenium working and then move on to more mature Selenium libraries like Remote control (Selenium 1.0) and Web Driver (Selenium 2.0).
Though most commercial tools have built-in capabilities for test reporting, error recovery mechanisms and Selenium does not provide any such features by default. But given the rich set of languages available with Selenium it very easy to emulate such features.
What is the set of tools available with Selenium?
Selenium has four set of tools – Selenium IDE, Selenium 1.0 (Selenium RC), Selenium 2.0 (WebDriver) and Selenium Grid. Selenium Core is another tool but since it is available as part of Selenium IDE as well as Selenium 1.0, it is not used in isolation.
Which Selenium Tool should I use?
It entirely boils down to where you stand today in terms of using Selenium. If you are entirely new to Selenium then you should begin with Selenium IDE to learn Selenium location strategies and then move to Selenium 2 as it is the most stable Selenium library and future of Selenium. Use Selenium Grid when you want to distribute your test across multiple devices. If you are already using Selenium 1.0 than you should begin to migrate your test scripts to Selenium 2.0
What is Selenium IDE?
Selenium IDE is a Firefox plug-in which is (by and large) used to record and replay test is Firefox browser. Selenium IDE can be used only with Firefox browser.
Which language is used in Selenium IDE?
Selenium IDE uses HTML sort of language called Selenese. Though other languages (java, c#, PHP etc) cannot be used with Selenium IDE, Selenium IDE lets you convert test in these languages so that they could be used with Selenium 1.0 or Selenium 2.0
What is Selenium 1.0?
Selenium 1.0 or Selenium Remote Control (popularly known as Selenium RC) is the library available in wide variety of languages. The primary reason for advent of Selenium RC was incapability of Selenium IDE to execute tests in the browser other than Selenium IDE and the programmatical limitations of language Selenese used in Selenium IDE.
What is Selenium 2.0?
Selenium 2.0 also known as WebDriver is the latest offering of Selenium. It provides
· better API than Selenium 1.0
· supports more UI complicated UI operations like drag and drop
What are the element locators available with Selenium which could be used to locate elements on the webpage?
There are mainly 4 locators used with Selenium –
· HTML id
· HTML name
· XPath locator and
· CSS locators
What is Selenium Grid?
Selenium grid lets you distribute your tests on multiple machines and all of them at the same time. Hence you can execute test on IE on Windows and Safari on Mac machine using the same test script (well, almost always). This greatly helps in reducing the time of test execution and provides quick feedback to stack holders.
Selenium IDE Questions
What are two modes of views in Selenium IDE?
Selenium IDE can be opened either in sidebar (View > Sidebar > Selenium IDE) or as a pop up window (Tools > Selenium IDE). While using Selenium IDE in browser sidebar it cannot record user operations in a popup window opened by the application.
Can I control the speed and pause test execution in Selenium IDE?
Selenium IDE provides a slider with Slow and Fast pointers to control the speed of execution.
Where do I see the results of Test Execution in Selenium IDE?
Result of test execution can be viewed in log window in Selenium IDE –
Where do I see the description of commands used in Selenium IDE?
Commands of description can be seen in Reference section –
Can I build test suite using Selenium IDE?
Yes, you can first record individual test cases and then group all of them in a test suite. Following this entire test suite could be executed instead of executing individual tests.
What verification points are available with Selenium?
There are largely three type of verification points available with Selenium –
· Check for page title
· Check for certain text
· Check for certain element (text box, drop down, table etc)
I see two types of the check with Selenium – verification, and assertion, what’s the difference between tow?
· A verification check lets test execution continue even in the wake of failure with the check, while assertion stops the test execution. Consider an example of checking the text on the page, you may like to use verification point and let test execution continue even if the text is not present. But for a login page, you would like to add an assertion for the presence of text box login as it does not make sense continuing with test execution if login text box is not present.
I don’t see checkpoints added to my tests while using Selenium IDEL, how do I get them added to my tests?
You need to use context menu to add checkpoints to your Selenium IDE tests –
How do I edit tests in Selenium IDE?
There are two ways to edit tests in Selenium IDE; one is the table view while other looking into the source code of recorded commands –
What is the syntax of the command used in Selenium?
There are three entities associated with a command –
· Name of Command
· Element Locator (also known as Target)
· Value (required when using echo, wait etc)
There are tons of Selenium Command, am I going to use all of them
This entirely boils down to operations you are carrying out with Selenium. Though you would definitely be using following Selenium Commands more often –
· Open: opens a web page.
· click/clickAndWait: click on an element and waits for a new page to load.
· Select: Selects a value from a drop down value.
· verifyTitle/assertTitle: verifies/asserts page title.
· verify/assert ElementPresent: verifies/asserts presence of element, in the page.
· verify/assert TextPresent verifies/asserts expected text is somewhere on the page.
How do I use HTML id and name while using Selenium IDE
Html id and name can be used as it is in selenium IDE. For example, Google search box has name – “q” and id – “list-b” and they can be used as target in Selenium IDE –
What is XPath? When would I have to use XPath in Selenium IDE?
XPath is a way to navigate in the xml document and this can be used to identify elements in a web page. You may have to use XPath when there is no name/id associated with the element on the page or only partial part of name/ide is constant.
Direct child is denoted with – /
Relative child is denoted with – //
Id, class, names can also be used with XPath –
· //input[@class=’ lst’]
If only part of id/name/class is constant than “contains” can be used as –
What is CSS location strategy in Selenium?
CSS location strategy can be used with Selenium to locate elements, it works using cascade style sheet location methods in which –
Direct child is denoted with – (a space)
Relative child is denoted with – >
Id, class, names can also be used with XPath –
· css=input[id=’lst-ib’] or input#lst-ib
· css=input[class=’ lst’] or input.lst
If only part of id/name/class is constant than “contains” can be used as –
· css=input[id*=’ lst-ib ‘)]
Element location strategy using inner text
· css = a:contains(‘log out’)
There is id, name, XPath, CSS locator, which one should I use?
If there are constant name/id available than they should be used instead of XPath and CSS locators. If not then CSS locators should be given preference as their evaluation is faster than XPath in most modern browsers.
I want to generate random numbers, dates as my test data, how do I do this in Selenium IDE?
And for date –
Can I store the result of an evaluation and use it later in my test?
You can use “store” command to achieve this. You can save the result of an evaluation in a variable and use it later in your Selenium IDE script. For example, we can store value from a text box as following, and later use it to type it in another text box –
I have stored the result of an evaluation; can I print it in IDE to check its value?
You can use echo command as following to check the stored value in Selenium IDE –
You could use verify/assertAlert to check the presence of alert on the page. Since selenium cannot click on “Ok” button on js alert window, the alert itself does not appear on the page when this check is carried out.
Selenium has recorded my test using XPath, how do I change them to CSS locator?
You can use drop down available next to Find in Selenium to change element locator used by Selenium –
I have written my own element locator, how do I test it?
You can use Find button of Selenium IDE to test your locator. Once you click on it, you would see element being highlighted on the screen provided your element locator is right Else one error message would be displayed in the log window.
I have written one js extension; can I plug it in Selenium and use it?
You could specify you js extension in “Options” window of Selenium IDE –
How do I convert my Selenium IDE tests from Selenese to another language?
You could use Format option of Selenium IDE to convert tests in another programming language –
I have converted my Selenium IDE tests to java but I am not able to execute them, execution options, as well as Table tab of Selenium IDE, is disabled.
This is because Selenium IDE does not support execution of the test in any other language than Selenese ( the language of Selenium IDE). You can convert Selenium IDE in a language of your choice and then use Selenium 1.0 to execute these tests in that language.
I want to use only Selenese as my test script language but still want to execute tests in other browsers, how do I do that?
You can execute you Selenese test in another browser by specifying the “-htmlSuite” followed by the path of your Selenese suite while starting the Selenium Server. Selenium Server would be covered in details in question about Selenium RC.
I have added one command in the middle of the list of commands, how do I test only this new command?
You can double click on newly added command and Selenium IDE would execute only that command in the browser.
Can I make Selenium IDE tests begin test execution from a certain command and not from the very first command?
You could set a command as “start” command from context menu. When a command is set as start command then a small green symbol appears before the command. The Same context menu can be used to toggle this option.
Are there other tools available outside Selenium IDE to help me tests my element locators
You could XPath checker –to test you XPath locators and Firefinder (a firebug add-on) to test you CSS locators –
Firefinder can also be used to test XPath locators.
What is an upcoming advancement in Selenium IDE?
The latest advancement in Selenium IDE would be to have capabilities of converting Selenium IDE tests in Webdriver (Selenium 2.0) options. This would help to generate quick and dirty tests for Selenium 2.0
How can I use looping option (flow control) is Selenium IDE
Selenese does not provide support for looping, but there is an extension which could be used to achieve same.
This extension can be added under “Selenium IDE Extension” section to use loop feature in Selenium IDE.
Can I use screen coordinate while using click command? I want to click at the specific part of my element.
You would need to use clickAT command to achieve. clickAt command accepts element locator and x, y coordinates as arguments –
How do I verify the presence of drop-down options using Selenium?
Use assertSelectOptions as following to check options in a drop-down list –
Can I get data from a specific HTML table cell using Selenium IDE?
Use storeTable command to get data from a specific cell in an HTML table, following example store text from cell 0,4 from an HTML table –
I want to make Selenium IDE record and display CSS locator followed by other locators, is it possible to give high priority to CSS locator in Selenium IDE?
You can change default behavior of Selenium IDE > element locator preference by crating js file with following–
LocatorBuilders.order = [‘css:name’, ‘css:id’, ‘id’, ‘link’, ‘name’, ‘xpath:attributes’];
And add this file under “Selenium IDE Extension” under Selenium Options.
My application has dynamic alerts which don’t always appear, how do I handle them?
If you want to simulate clicking “ok “ on alert than use – chooseOkOnNextConfirmation and if you want to simulate clicking “cancel” on alert than use – chooseCancelOnNextConfirmation ( )
Can I right click on a locator?
You can use the command – contextMenu ( locator) to simulate a right click on an element in a web page.
How do I capture a screenshot of the page using Selenium IDE?
Use command – captureEntirePageScreenshot to take a screenshot of the page.
I want to pause my test execution after the certain command.
Use pause command which takes time in milliseconds and would pause test execution for specified time – pause ( waitTime )
I used open command to launch my page, but I encountered timeout error.
This happens because open commands wait for only 30 seconds for a page to load. If your application takes more than 30 sec then you can use “setTimeout ( timeout )” to make selenium IDE wait for specified time, before proceeding with test execution.
What’s the difference between type and typeKeys commands?
type command simulates enter operations at one go while typeKeys simulates keystroke key by key.
typeKeys could be used when typing data in a text box which bring options (like Google suggestion list) because such operation is not usually simulated using type command.