Multiple buttons with same name and id

1,563 views
Skip to first unread message

Ravi

unread,
Oct 30, 2012, 10:55:41 AM10/30/12
to seleniu...@googlegroups.com
Hi All,
 Am new to selenium.I have got multpile buttons in my jsp with same name and id.I need to automate a test case where am clicking mutliple buttons.Please let me know how to automate it.

<input type="submit" id="button" value="Edit"/>


Oscar Rieken

unread,
Oct 30, 2012, 11:08:32 AM10/30/12
to seleniu...@googlegroups.com
id's should be unique 

you can try collecting all of the same elements and them select the one you want. but how do you know? maybe go up to the container the submit button exists in and see if you can locate that then locate the submit


if you cant get that fixed i suggest posting some more html around what you are trying to do

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/8VCiKnEYTRAJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ravi Kumar H M

unread,
Oct 30, 2012, 11:25:19 AM10/30/12
to seleniu...@googlegroups.com
Its simple 
<input type="submit" id="button" value="Edit"/>
<input type="submit" id="button" value="Edit"/>
<input type="submit" id="button" value="Edit"/>
I have same edit button,but under different forms.I tried to click the button in numersous ways as follows

		selenium.click("xpath=//input[@id='button' and @value='Edit']");
    selenium.click("xpath=//input[@id='button'][1]");
selenium.click("xpath=//input[@id='button' and @value='Edit'][1]");
Nothing is worrying.Can anyone help me automate this.Thanks in advance

--
Regards,
Ravi Kumar H M

Oscar Rieken

unread,
Oct 30, 2012, 12:00:12 PM10/30/12
to seleniu...@googlegroups.com
do the forms have different names or id's 

@browser.find_element(tag_name: "form1").find_element(id: "button").click

or have the devs change the id's to make them unique for each form

Mark Collin

unread,
Oct 30, 2012, 4:15:13 PM10/30/12
to seleniu...@googlegroups.com

You have found a bug, report it and get the devs to fix it.

 

If they refuse to fix it they suck, the whole codebase will likely suck, the project most likely sucks too.

 

Life’s too short to work with teams that suck.  Your will find work much more enjoyable when you work with an awesome team!

Ross Patterson

unread,
Oct 30, 2012, 5:00:39 PM10/30/12
to seleniu...@googlegroups.com

The correct syntax for finding the n’th item with an identical XPath on the page is “xpath=(...path...)[n]”, for example “xpath=(//input[@id='button' and @value='Edit'])[2]” for the second button with both the id “button” and the value “Edit”.  Note the placement of the parentheses – that’s the key – and the fact that in XPath, the first item is numbered “1” (not “0” as some programmers expect).

 

Ross

Mark Collin

unread,
Oct 31, 2012, 2:29:53 AM10/31/12
to seleniu...@googlegroups.com

Really, don’t even bother trying to automate bugs.

 

If there is a bug in the code the test should fail, if you automate around it, it’s quite likely the bug will not get fixed. 

 

If you go around “fixing” your tests so that they pass when legitimate problems are found you are not testing you are wasting your time.  Your test suite is now worthless because it is not catching errors and people will quite legitimately run your suite in the future and assume everything is fine when the test passes.

 

DO NOT AUTOMATE AROUND BUGS TO MAKE YOUR TEST PASS!

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Randy Harding
Sent: 31 October 2012 00:59
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: Multiple buttons with same name and id

 

Selenium can usually find the elements, so something else may be wrong. Do you need to call a function related to switch_to locate the elements?  Can you create a test case in the IDE, export it, and then post it here?  Then we can see the basic framework for what you need to do including any switch_to statements.  Let us know instructions on the IDE and test case I am referring to

--

You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/l92wJ7w75DcJ.

Reply all
Reply to author
Forward
0 new messages