Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» how to connect DB in selenium webriver
Fri Oct 06, 2017 4:09 pm by anbarasi

» How find any text in browser screen and click on it?
Thu Oct 05, 2017 2:02 pm by sandeepkommineni

» Selenium Webdriver
Tue Oct 03, 2017 1:35 pm by PiyushBiswas

» GRID setup tutorial.
Wed Sep 27, 2017 4:29 pm by johnyapp

» Drag & Drop Between Windows Using Selenium Driver
Wed Sep 27, 2017 2:10 pm by 26rondel

» Check if window is closed / verify input
Sat Sep 23, 2017 10:21 pm by brainstir

» How to work on pages with AJAX in selenium?
Mon Sep 18, 2017 6:08 pm by azharuddin

» pause test until user press a key like F2
Wed Aug 09, 2017 11:10 pm by djnforce

» Selecting the input for auto populating element
Sat Jul 29, 2017 7:53 pm by kdabbara

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

how to select checkbox whose id is not known or dynamic with selenium RC

View previous topic View next topic Go down

how to select checkbox whose id is not known or dynamic with selenium RC

Post by narendercb on Tue Jun 25, 2013 8:44 pm

Hi All,
I need to select checkbox in the web application whose id is  appended dynamically,Can you please help me

Thanks,
Narender chary

following is the html code snip from the web application
--------------------------‹‹
<table id="someid">
<tr>
<td>
<input id="someDynamicId" type="checkbox" .....>mycheckbox
</td>
</tr>
</table>

my requirement is
1.check checkbox whose value/lable is mycheckbox and if this matches select this checkbox
2.i need to do this in Selenium RC.

narendercb

Posts : 8
Join date : 2013-06-25

Back to top Go down

Re: how to select checkbox whose id is not known or dynamic with selenium RC

Post by mail2prassad on Tue Jun 25, 2013 10:47 pm

The following block of code should do, but this is WebDriver not RC. The similar logic should work in RC also.


Code:
//To get the check box with value MY_CHECKBOX_VALUE
WebElement checkBox = driver.findElement(By.xpath("//input[@type = 'checkbox' and @value = '<MY_CHECKBOX_VALUE>']"));

//To select the checkbox
if(checkBox != null)
checkBox.click();

mail2prassad
Amateur
Amateur

Posts : 41
Join date : 2013-06-05

Back to top Go down

Re: how to select checkbox whose id is not known or dynamic with selenium RC

Post by narendercb on Tue Jun 25, 2013 11:35 pm

Hi,
the above mention solution driver.findElement(By.xpath("//input[@type='checkbox' and @value='my_checkbox_value']")) will work if html code like below

<td>
<input id="someDynamicId" type="checkbox" .....>mycheckbox
</td>

but hovewer my actual html source  is something like below
--------
<table id="someid">
<tr>
<td>
<input id="someDynamicId" type="checkbox" .....>
</td>
<td>mycheckbox</td>
</tr>
</table>

Please suggest

narendercb

Posts : 8
Join date : 2013-06-25

Back to top Go down

Re: how to select checkbox whose id is not known or dynamic with selenium RC

Post by narendercb on Thu Jun 27, 2013 1:44 am

Hi,
i have done following steps and its worked
1.read all the check box id's in web page like below
 int checkboxCount = selenium.getXpathCount("//input[@type='checkbox']").intValue();
              String checkBoxIds[]=new String[checkboxCount];
for (int i = 1; i < checkboxCount + 1; i++) {
            System.out.println(selenium.getAttribute("//body/descendant::input[@type='checkbox'][" + i + "]@id"));
            if (selenium.getAttribute("//body/descendant::input[@type='checkbox'][" + i + "]@id").startsWith("check")) {
                checkBoxIds[i-1]=selenium.getAttribute("//body/descendant::input[@type='checkbox'][" + i + "]@id");
            }
            
        }
            
        }

2.Iterate all the rows in the table and select the check box whose lable is matched with the requirement
    Number num =selenium.getXpathCount("//html/body/div/div[1]/table[1]/tbody/tr[2]/td[2]/div[1]/div[4]/div[3]/table/tbody[2]/tr/");
            int i= num.intValue();
            for (int j = 1; j <i+1; j++) {
                      if (selenium.getText("//html/body/div/div[1]/table[1]/tbody/tr[2]/td[2]/div[1]/div[4]/div[3]/table/tbody[2]/tr["+j+"]/td[4]").equals(messageToDelete)) {
                           selenium.check("//input[@id='"+checkBoxIds[j-1]+"']");
                   }
            }
            selenium.click("id_of_target");

Thanks,

narendercb

Posts : 8
Join date : 2013-06-25

Back to top Go down

Re: how to select checkbox whose id is not known or dynamic with selenium RC

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum