How to verify value in drop down list.
We somehow manage to find the element on the page but its difficult to fund element with some specific attributes.
Take an example How to find some value is in drop down list or now? To find element drop down is easy but to find a drop down having some specific
value in their list is difficult.
Go to www.ebay.in you will see there is drop down along with search text box.
How to veify a specific value "Collectibles" is in drop down list.
How to select the value in drop down using regular expression.
There are situation when we need to select the drop down value with some partial text .
With the help of regular expression we can select the drop down value
Selenium is unable to type in iframe. But we can write in it by identifying the iframe using css.
When you write any mail in gmail you can see the body is a iframe we can write in it using below commands Selenium IDE
<tr>
<td>storeEval</td>
<td>var bodytext=" Writing text in iframe body with the help of http://automationtricks.blogspot.com "; var iframe_locator="css=table:contains('Subject:') +* iframe"; var iframe_body=selenium.browserbot.findElement(iframe_locator).contentWindow.document.body; if (browserVersion.isChrome){ iframe_body.textContent=bodytext; } else if(browserVersion.isIE){ iframe_body.innerText=bodytext; }</td>
<td></td>
</tr>
Selenium RC.
String = selenium.getEval("var bodytext=\" Writing text in iframe body with the help of http://automationtricks.blogspot.com \"; var iframe_locator=\"css=table:contains('Subject:') +* iframe\"; var iframe_body=selenium.browserbot.findElement(iframe_locator).contentWindow.document.body; if (browserVersion.isChrome){ iframe_body.textContent=bodytext; } else if(browserVersion.isIE){ iframe_body.innerText=bodytext; }");
How to share a variable in more than one test case.
We Create a variable in one test case and use in another test cases. If these test cases are running seperately and independetely then those variable
cannot shared. But if we run all test cases in test suite then one varaible declared in one testcase can be used in another
Follow these steps.
Create your test cases saparetly and call them in a test suite. 1.Create first test case
Test1.html
<html>
<head></head>
<body>
<table>
<tbody>
<tr>
<td>Test suite for sharing variable among test cases </td>
</tr>
<tr>
<td><a target="testFrame" href="test1.html">test1</a></td>
</tr>
<tr>
<td><a target="testFrame" href="test2.html">test2</a></td>
</tr>
<tr>
<td><a target="testFrame" href="test3.html">test3</a></td>
</tr>
</tbody>
</table>
</body>
</html>
Run your test suite and you will see the variable vartest1 decalred in testcase1 being used in testcases2
and variable vartest2 declared in testcase2 being used in testcase3.
We can get the browser name, version and operating system name and version with the following commands in selenium RC.
Below code is tested in Mozilla Firefox Browser Name
System.out.println(selenium.getEval("navigator.appCodeName;"));
Mozilla
There are some scenarios where we need to input when our web application need external input data by opening input prompt dialog box. To handle these dialog boxes in automation is tricky task. We can handle these situation with below codes.
Html file is at the bottom
selenium.open("Input_prompt_TestCase.html");
Verify there is no input dilog present while opening this file
assertTrue(!selenium.isPromptPresent());
When then Input prompts select NO first time by the command answerOnNextPrompt|no|
selenium.answerOnNextPrompt("no");
Now click to open the input dialog by clicking the link "Click here to open input dialog"
selenium.click("promptdialog");
Now verify prompt presents or not with the command verifyPromptPresent||
assertTrue(selenium.isPromptPresent());
If it takes time to open the prompt then we can wait till 1 minute with the below code.
boolean Bool = false;
for (int second = 0; second < 60; second++) {
try {
if ((selenium.isPromptPresent())) {
Bool = true;
break;
}
}
catch (Exception ignore) {
}
pause(1000);
}
assertTrue(Bool);
Now after 1 minute verify the prompt presents or not with the command assertPromptPresent||
assertTrue(selenium.isPromptPresent());
If it verifies prompt is there then verify the text what is on prompt with the command
verifyPrompt|Type 'automationtricks' and click OK|
verifyEquals("Type 'automationtricks' and click OK", selenium.getPrompt());
You can also verify the title of input prompt with the command verifyTitle|Test Prompt|
verifyEquals("*Testcases for input Prompt", selenium.getTitle());
Now you just enter automationtricks in input promt with this command
answerOnNextPrompt|automationtricks|
selenium.answerOnNextPrompt("automationtricks");
and then click on ok with command clickAndWait|promptdialog|
selenium.click("promptdialog");
Now you can see the result based on your input
selenium.waitForPageToLoad("5000");
verifyTrue(selenium.isTextPresent("You have entered automationtricks!"));
For Selenium IDE user : How to handle prompt in selenium IDE
We can test based on attributes of elements by using css. We can use regular expression in css attributes to identify the element.
If your element is in this css format.
This will store the "barfoo" in str variable because element <a name="barfoo">barfoo</a> name ends with "foo"
How to store the text of and element which css attributes starts with any letters and ends with any letters but containing some specific letters in middle.
Ex. in above element how to store the text whose element name ends with any letter and ends with any letter but containing some specific letters "zoo"
<div id="combinatorTest">this is the parent element. <span id="firstChild">this is a child element <a>and grandson element</a></span>, <span>another child element</span>, <span>last child element<span></span></span></div>
How to store the text of preceding combinator element in RC