If your element is in this css format.
<div id="css3test"><a name="foobar">foobar</a><a name="barfoo">barfoo</a><a id="foobar" name="foozoobar">foozoobar</a></div>
Ex. in above element how to store the text whose element name start with "foo"
Selenium IDE
<tr>
<td>storeText</td>
<td>css=a[name^="foo"]</td>
<td>str</td>
</tr>
Selenium RC
String str = selenium.getText("css=a[name^=\"foo\"]");
This will store the "foobar" in str variable because element <a name="foobar">foobar</a> name start with "foo" Ex. in above element how to store the text whose element name ends with "foo"
Selenium IDE
<tr>
<td>storeText</td>
<td>css=a[name$="foo"]</td>
<td>str</td>
</tr>
Selenium RC
String str = selenium.getText("css=a[name$=\"foo\"]");
This will store the "barfoo" in str variable because element <a name="barfoo">barfoo</a> name ends with "foo"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"
Selenium IDE
<tr>
<td>storeText</td>
<td>css=a[name*="zoo"]</td>
<td>str</td>
</tr>
Selenium RC
String str = selenium.getText("css=a[name*=\"zoo\"]");
This will store the "foozoobar" in str variable because element <a name="foozoobar">foozoobar</a> name contains "zoo" in the middle.There is another method to store
String str = selenium.getText("css=a:contains(\"zoo\")");
Lets say your element is in this format.
<a alt="foo" class="a2" href="#id2" name="name1" id="id2">this is the <b>second</b> <span selenium:foo="bar">element</span></a>
then if you want to store "this is the second element" in a variable called str theSelenium IDE
<tr>
<td>storeText</td>
<td>css=a[name*="name"][alt="foo"]</td>
<td>str</td>
</tr>
Selenium RC
String str = selenium.getText("css=a[name*=\"name\"][alt=\"foo\"]");
If you want to store only "element" from above element then use below codeSelenium IDE
<tr>
<td>storeText</td>
<td>css=a[name*="name"][alt="foo"]>span</td>
<td>str</td>
</tr>
Selenium RC
String str = selenium.getText("css=a[name*=\"name\"][alt=\"foo\"]>span");
Lets say your element looks like
<div id="structuralPseudo">
<span>span1</span>
<span>span2</span>
<span>span3</span>
<span>span4</span>
<div>div1</div>
<div>div2</div>
<div>div3</div>
<div>div4</div>
</div>
to identify the element within the element we will use
css=div#structuralPseudo :nth-child(n)
1. To identify first element in pseudo element id="structuralPseudo and store its text.
String str = selenium.getText("css=div#structuralPseudo :nth-child(n)");
this will store "span1" in str variable.2. To identify second element in pseudo element id="structuralPseudo and store its text.
String str = selenium.getText("css=div#structuralPseudo :nth-child(2n)");
this will store "span2" in str variable.3. To identify third element in pseudo element id="structuralPseudo and store its text.
String str = selenium.getText("css=div#structuralPseudo :nth-child(3n)");
this will store "span3" in str variable....
...
...
8.. To identify the last element in pseudo element id="structuralPseudo and store its text.
String str = selenium.getText("css=div#structuralPseudo :nth-child(3n)");
this will store "div4" in str variable.9. But you can access first and last child directly
to access first element
String str = selenium.getText("css=div#structuralPseudo :first-child");
this will store "span1" in str variableTo access last element
String str = selenium.getText("css=div#structuralPseudo :last-child");
this will store "div4" in str variableFor more details about css selector please visit .
http://www.w3.org/TR/CSS2/selector.html
<input type="text" disabled="true" value="disabled" name="disabled">
assertTrue(selenium.isElementPresent("css=input[type=\"text\"]:disabled"));
<input type="checkbox" checked="true" value="checked" name="checked">
assertTrue(selenium.isElementPresent("css=input[type=\"checkbox\"]:checked"));
Hi,
ReplyDeleteFirst of all, your post is really nice and useful.
Just having one question, suppose that the contents is dynamically generated, can I get the number of divs or retrieve them in an array ?
Thanks,
AA
superb!
ReplyDeletewelldone
ReplyDeleteThank everyone for encouraging me to write blog . Please let me know if you some specific question and requirement
ReplyDeleteNiraj
Thanks
ReplyDeleteThis blog was... how do I say it? Relevant!! Finally I have found something which
ReplyDeletehelped me. Kudos!
my weblog ... airplane games simulator
What ever may be the testing, test data is the crucial part for the execution of qualitative delivery.Find below the blog for the test data preparation tips.
ReplyDeletehttp://softwaretestingterminologies.blogspot.in/2017/03/tips-to-design-your-test-data.html
People willing to get the indepth knowledge in getting framework such as TestNG,jenkins,Maven and POM should get properly get best selenium training in chennai
ReplyDeleteI enjoy what you guys are usually up too. This sort of clever work and coverage! Keep up the wonderful works guys I’ve added you guys to my blog roll.
ReplyDeleteAWS Course Training in Chennai |Best AWS Training Institute in Chennai
Devops Course Training in Chennai |Best Devops Training Institute in Chennai
Selenium Course Training in Chennai |Best Selenium Training Institute in Chennai
Java Course Training in Chennai | Best Java Training Institute in Chennai