Locate an element which have same name and same atrributes in selenium

Automation using selenium is a great experience. It provides many way to identif an object or element on the web page.
But sometime we face the problems of idenfying the objects on a page which have same attributes. When we get more than
one element which are same in attribute and name like multiple check boxes with same name and same id. More than one button having
same name and ids. There are no way to distingues those element. In this case we have problem to instruct selenium to identify a perticular
object on a web page.
I am giving you a simple example . In the below HTML source there are 6 check boxes are there having same type and same name.
It is really tough to select third or fifth.

Thare are some function we can use in Xpath to identify the abject in above cases.
An XPath expression can return one of four basic XPath data types:

* String
* Number
* Boolean
* Node-set

XPath Type : Functions

Node set : last(), position(), count(), id(), local-name(), namespace-uri(), name()

String : string(), concat(), starts-with(), contains(), substring-before(), substring-after(), substring(), string-length(), normalize-space(), translate()

Boolean : boolean(), not(), true(), false(), lang()

Number : number(), sum(), floor(), ceiling(), round()

I will show you how we can use some of these above functions in xpath to identify the objects.
 
<html>
<body>
<input type='checkbox' name='chk'>first
<br><input type='checkbox' name='chk'>second
<br><input type='checkbox' name='chk'>third
<br><input type='checkbox' name='chk'>forth
<br><input type='checkbox' name='chk'>fifth
<br><input type='checkbox' name='chk'>sixth
</body>
</html>

selenium.click("xpath=(//input[@type='checkbox'])[last()]");

selenium.click("xpath=(//input[@type='checkbox'])[position()=2]");

Click on first link
selenium.click("xpath=(//a[@name='a1'])[position()=1]");
selenium.waitForPageToLoad("80000");
Click on second link
selenium.click("xpath=(//a[@name='a1'])[position()=2]");
selenium.waitForPageToLoad("80000");
Click on last link
selenium.click("xpath=(//a[@name='a1'])[last()]");
selenium.waitForPageToLoad("80000");
Click on thrid link
selenium.click("xpath=(//a[@name='a1'])[position()=3]");
selenium.waitForPageToLoad("80000");

How to Write in iFrame in selenium

When you write any mail in gmail you can see the body is a iframe we can write in it using

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;
 }
");


27 comments:

  1. If all check boxes size increasing or decreasing dynamically and all check boxes having same values then how to check each and every check boxes.

    ReplyDelete
  2. This is very informative blog and nice article , I really like your technique of writing a blog. More screenshots gives the clear representation.. I book marked it to my bookmark site list and will be checking back in the near future Selenium Training in Chennai gives you the entire stuff about all the Selenium Components. Among that, the above mentioned IDE is the baby steps to learn other 2 components.

    ReplyDelete
  3. Hello Ramesh,


    A nice article here with some useful tips for beginners. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them. Here are some more link which I also useful for freshers.
    Free Selenium Tutorials |

    ReplyDelete
  4. Great read, Selenium has brought evolution to automation world.Thanks for taking a time to share a wonderful article.I share this website my office mate and friend circle.I'll be to provide that real-time Selenium Automation Training in Chennai.We having to provide that Latest version selenium 3.0.
    Selenium Training in Chennai

    ReplyDelete
  5. Thanks for your correct information,you are providing some good helpful information.

    Online Robot Framework Training

    ReplyDelete
  6. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Python training in marathahalli
    Python training in pune
    AWS Training in chennai

    ReplyDelete
  7. A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts read this.

    Data Science training in Chennai
    Data science training in bangalore
    Data science training in pune
    Data science online training

    ReplyDelete
  8. You know what you’re talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?
    industrial safety course in chennai

    ReplyDelete
  9. You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in btm

    ReplyDelete
  10. Thank you for sharing such a nice and interesting blog with us. Hope it might be much useful for us. keep on updating...!!

    Article submission sites
    Guest posting sites

    ReplyDelete
  11. It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
    python Training institute in Pune
    python Training institute in Chennai
    python Training institute in Bangalore

    ReplyDelete
  12. Title:
    No.1 Oracle Training Institute in Chennai | Infycle Technologies


    Get Oracle Certification in Chennai for making your career as a shining sun with Infycle Technologies. Infycle Technologies is the best Oracle training institute in Chennai, providing complete hands-on practical training of professional specialists in the field. In addition to that, it also offers numerous programming language tutors in the software industry such as Big Data, Java, Python, AWS, Hadoop, etc. Once after the training, interviews will be arranged for the candidates, so that, they can set their career without any struggle. Of all that, 200% placement assurance will be given here. To have the best career, call 7502633633 to Infycle Technologies and grab a free demo to know more.

    best training institute in chennai

    ReplyDelete
  13. Infycle Technologies, the best software training institute in Chennai offers the best Python training in Chennai for tech professionals and freshers. In addition to the Python Training Course, Infycle also offers other professional courses such as Data Science, Oracle, Java, Power BI, Digital Marketing, Big Data, etc., which will be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7502633633 to get more info and a free demo.

    ReplyDelete
  14. Want to do a No.1 Data Science Course in Chennai with a Certification Exam? Catch the best features of Data Science training courses with Infycle Technologies, the best Data Science Training & Placement institutes in and around Chennai. Infycle offers the best hands-on training to the students with the revised curriculum to enhance their knowledge. In addition to the Certification & Training, Infycle offers placement classes for personality tests, interview preparation, and mock interviews for clearing the interviews with the best records. To have all it in your hands, dial 7504633633 for a free demo from the experts.

    ReplyDelete
  15. This post is so interactive and informative.keep update more information...
    DevOps course in Tambaram
    DevOps Training in Chennai

    ReplyDelete